gpt4 book ai didi

ios - 将 UILabel 滑动到 View Controller 上

转载 作者:行者123 更新时间:2023-11-29 10:59:31 25 4
gpt4 key购买 nike

我正在尝试以平滑的滑动类型动画从 UIViewController 顶部的起始位置移动 UILabel,以便它在 View 加载时从顶部向下滑动,然后在 y 位置停止大约 10 秒. 10 秒后,我想再次滑出 View 。

-(void) animateInstructionLabel
{
float newX = 50.0f;
float newY = 100.0f;

[UIView transitionWithView:self.lblInstruction
duration:10.0f
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(newX, newY);
}
completion:^(BOOL finished) {
// Do nothing
}];
}

但我不知道如何进行 10 秒延迟,然后在上面的方法内返回。最终结果是我希望它成为一个看起来像通知的标签,然后再次移出屏幕。

有人可以帮我把上面描述的这些部分放在一起吗?

编辑

我是根据下面的回答添加的:

-(void) animateInstructionLabel
{
float newX = lblInstruction.frame.origin.x;
float newY = 20.0f;

lblInstruction.center = CGPointMake(lblInstruction.frame.origin.x, -20.0f);
lblInstruction.bounds = CGRectMake(lblInstruction.frame.origin.x, -20.0f, 650.0f, 40.0f);

[UIView animateWithDuration:3.0f
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(newX, newY);
}
completion:^(BOOL finished) {
[UIView animateWithDuration:5.0f
delay:5.0
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(newX, -20);
}
completion:^(BOOL finished) {
// Do nothing
}
];
}
];
}

但是即使我在动画开始之前将 label.center 设置在屏幕外,我也看到它从 viewcontroller 的左上角移动到 viewcontroller 的中心。它没有保持在动画开始之前应该设置的 x 位置。

最佳答案

尝试在你的动画 block 之后添加这个(oldX,oldY 是旧坐标,在动画标签之前):

double delayInSeconds = 10.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView transitionWithView:self.lblInstruction
duration:10.0f
options:UIViewAnimationCurveEaseInOut
animations:^(void) {
lblInstruction.center = CGPointMake(oldX, oldY);
}
completion:^(BOOL finished) {
// Do nothing
}];
});

关于ios - 将 UILabel 滑动到 View Controller 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16628836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com