【问题标题】:animate 3 views one after the other一个接一个地为 3 个视图设置动画
【发布时间】:2016-04-18 10:01:11
【问题描述】:

我正在尝试一个接一个地为 3 个不同的视图设置动画以显示同步。如何使用 CAAnimation 实现这一点。 尝试使用 Gcd 执行此操作,一个接一个地调用 3 个方法,其中我显示第一个圆圈并隐藏其他圆圈。但遇到了一些问题。

【问题讨论】:

    标签: ios iphone xcode caanimation


    【解决方案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;
    }
    
    
     }
    

    希望这会有所帮助:)

    【讨论】:

    • 使用 NSTimer 阻塞 UI。还有其他方法吗?
    • 检查更新部分。这是计数器增量的一个小错误。尝试这样,它在我的演示中工作正常。 :)
    【解决方案2】:

    我推荐使用UIImageView.animationImages,它比动画更容易、更快、更省电。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-27
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-31
      相关资源
      最近更新 更多