动画3个视图一个接一个

时间:2016-04-18 10:01:11

标签: ios iphone xcode caanimation

我试图一个接一个地动画3个不同的视图来显示同步。如何使用CAAnimation实现这一点。 尝试使用Gcd一个接一个地调用3个方法,我显示第一个圆圈并隐藏其他圆圈。但是他遇到了一些问题。

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以在不使用动画的情况下执行此类操作 将标记设置为exa 1,2和3的三个视图

 NSTimer *timerLabelTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimerLabel) userInfo:nil repeats:YES];


 int counter = 0;
-(void)updateTimerLabel{



if (counter == 0) {

    UIView *tempView = [self.view viewWithTag:0];
    tempView.backgroundColor = [UIColor whiteColor];

    UIView *tempView1 = [self.view viewWithTag:1];
    tempView.backgroundColor = [UIColor blackColor];

    UIView *tempView2 = [self.view viewWithTag:2];
    tempView.backgroundColor = [UIColor blackColor];

}
if (counter == 1) {

    UIView *tempView = [self.view viewWithTag:0];
    tempView.backgroundColor = [UIColor blackColor];

    UIView *tempView1 = [self.view viewWithTag:1];
    tempView.backgroundColor = [UIColor whiteColor];

    UIView *tempView2 = [self.view viewWithTag:2];
    tempView.backgroundColor = [UIColor blackColor];

}

if (counter == 2) {

    UIView *tempView = [self.view viewWithTag:0];
    tempView.backgroundColor = [UIColor blackColor];

    UIView *tempView1 = [self.view viewWithTag:1];
    tempView.backgroundColor = [UIColor blackColor];

    UIView *tempView2 = [self.view viewWithTag:2];
    tempView.backgroundColor = [UIColor whiteColor];

    //removed counter = 0; from here
}

//Update
counter ++;

if (counter == 3) {
    counter =0;
}


 }

希望这会有所帮助:)

答案 1 :(得分:0)

我建议使用UIImageView.animationImages,它比动画更容易,更快速,耗能更少。