iOS 10 UILabels -> 1 UIView -> Loop through with Animation

人盡茶涼 提交于 2019-12-04 17:09:50

Edited with NSTimer instead of a loop.

counter is an ivar defined in the header.

 - (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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!