iOS 10 UILabels – > 1 UIView – >通过animation循环

我有10个UILabels ,也许一些UIImageViews 。 我想要在1个UIView中顺利地进行FadeOut&FadeIn转换,一个接一个地显示所有这些。

我知道把UIViewanimation放在for循环中将不起作用,因为animation是asynchronous完成的,不会产生适当的效果。 所以通常我会这样做的方式是将UIViewanimation链接在一起。 即一个元素animation完成后开始下一个。 对于3-4个元素,代码看起来不错。 像这样 –

 [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{ //do something with alpha here - first element } completion:^(BOOL finished){ [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{ //do something with alpha here - 2nd element} completion:^(BOOL finished){ ... } } 

但是对于十多个元素,它变得非常混乱。 怎么会这样做? 基本上我正在创build一个循环内容的UIView ,就像一个小部件。

NSTimer编辑而不是循环。

counter是头部定义的伊娃。

  - (void)viewDidLoad { [super viewDidLoad]; counter = 0; [NSTimer scheduledTimerWithTimeInterval:0.30 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES]; } - (void) timerTick:(NSTimer *)timer{ UIView *currentView = [self.view.subviews objectAtIndex:counter]; [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{ currentView.alpha = 1.0;} completion:^(BOOL finished){ [UIView animateWithDuration:0.25 animations:^{currentView.alpha = 0.0;}]; } ]; counter++; if (counter >= [self.view.subviews count]) { counter = 0; } }