animation标签延迟和持续时间Ios
所以我试图animation的标签,将开始与一个文本,然后一定的时间后,它会淡入淡出,新的文本来到屏幕,将在一定的时间后淡出,然后新的文本来。 我希望这个发生recursion。 我需要继续animation15秒,同样的事情发生在接下来的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调用mylabelanimation,然后在第四个animation完成块的末尾调用方法。
这里一切都按预期工作,但是最后一个animation到第一个animation转换并不像其他转换那样平滑 。 是因为我错过了什么 我真的无法弄清楚为什么会这样。
其次,是这样得到animation的正确方法。 还是有更好的方法来做到这一点?
你可能会发现这样更容易pipe理:
- (void)viewDidLoad { [super viewDidLoad]; self.counter = 0; self.animations = @[ @{@"Text":@"Hello", @"Duration":@(2.7)}, @{@"Text":@"Text 1", @"Duration":@(2.7)}, @{@"Text":@"Text 2", @"Duration":@(2.7)}, @{@"Text":@"Text 3", @"Duration":@(2.7)}, @{@"Text":@"Text 4", @"Duration":@(4.8)}, ]; [self animate:0]; } - (void)animate:(int)counter { self.counter = counter % self.animations.count; NSDictionary *item = self.animations[self.counter]; self.myLabel.alpha = 0; self.myLabel.text = item[@"Text"]; [UIView animateWithDuration:0.3 animations:^{ self.myLabel.alpha = 1.0; } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 delay:[item[@"Duration"] floatValue] options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.myLabel.alpha = 0.0; } completion:^(BOOL finished) { [self animate:++self.counter]; }]; }]; }
试试这个代码….
- (void)viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(MyLabelAnimation:) userInfo:nil repeats:NO]; } - (void)MyLabelAnimation:(NSTimer*) timer { self->mylabel.text = @"Hello"; [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) { [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(MyLabelAnimation:) userInfo:nil repeats:NO]; }]; }]; }]; }]; }]; }]; }]; }]; }
- 苹果开发人员拒绝 – 应用程序中使用订阅 – 商业 – 3.1.1
- 如何将iOS App Previewvideo升级到1080 x 1920?
- AppStore / iOS应用程序和解释代码 – 他们在哪里画线?
- Appstore Failure在二进制文件中没有体系结构。 Lipo未能检测到软件包可执行文件中的任何体系结构。“在SoftwareAssets / SoftwareAsset
- 苹果的审查程序可能会拒绝iOS应用程序中的fork()吗?
- 如何自动布局和部署应用程序到应用程序商店
- 在我的应用程序中embeddedApp Store
- 2014年4月/ iOS 7 – 有没有一种方法可以跟踪iOS应用程序的转换,将属性下载归入不同的广告系列来源,而无需使用IDFA?
- App Store中的多语言应用程序; 使用两个版本 – 或使用苹果本地化? (特例)