【发布时间】:2026-01-29 22:55:01
【问题描述】:
所以我试图为标签设置动画,该标签将以文本开头,然后在一定时间后它会消失,新文本出现在屏幕上,在一定时间后会消失,然后出现新文本。我希望这递归地发生。我需要继续动画 15 秒,接下来的 15 秒会发生同样的事情。
- (void)viewDidLoad {
[super viewDidLoad];
[self MyLabelAnimation];
}
- (void)MyLabelAnimation {
self.myLabel.text = @"Text 1";
[UIView animateWithDuration:0.3 animations:^{
self.myLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 delay:2.7 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.myLabel.alpha = 0.0;
} completion:^(BOOL finished) {
self.myLabel.text = @"Text 2";
[UIView animateWithDuration:0.3 animations:^{
self.myLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 delay:2.7 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.myLabel.alpha = 0.0;
} completion:^(BOOL finished) {
self.myLabel.text = @"Text 3";
[UIView animateWithDuration:0.3 animations:^{
self.myLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 delay:2.7 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.myLabel.alpha = 0.0;
} completion:^(BOOL finished) {
self.myLabel.text = @"Text 4";
[UIView animateWithDuration:0.3 animations:^{
self.myLabel.alpha = 1.0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.0 delay:4.8 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.myLabel.alpha = 0.0;
} completion:^(BOOL finished) {
[self MyLabelAnimation];
}];
}];
}];
}];
}];
}];
}];
}];
}
所以我在这里从 viewdidload 调用 mylabel 动画,然后在第 4 个动画的完成块末尾调用该方法。
这里一切都按预期工作,但最后一个动画到第一个动画过渡不平滑,因为其他过渡。是不是因为我错过了什么。我真的无法弄清楚为什么会这样。
其次,Is 是获得这样的动画的正确方法。或者有更好的方法吗?
【问题讨论】:
-
我也有同样的问题。
-
你们有谁知道如何在后台暂停动画并在前台再次恢复
-
我在这里得到了答案link
标签: ios objective-c iphone animation app-store