IOS动画,重复序列

标签 ios core-animation

我有一系列动画来显示三个不同的 UILabel 文本和转换。

    [UIImageView animateWithDuration:2.0 delay:0.1 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionRepeat animations:^{
        label.transform =CGAffineTransformMakeScale(1,1);
        label.text = [NSString stringWithFormat:@"Welcome %@!!!", name];
     }
     completion:^(BOOL finished){
       // code to run when animation completes
       // (in this case, another animation:)
      label.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.0, 0.0);
      [UIImageView animateWithDuration:3.0 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
          label.transform =CGAffineTransformMakeScale(1,1);
          label.text = [NSString stringWithFormat:@"Welcome %@!!!", name1];
        }
        completion:^(BOOL finished){
          [UIImageView animateWithDuration:1.0 delay:1.0 options:0
             animations:^{
                               label.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.0, 0.0);
               label.transform =CGAffineTransformMakeScale(1,1);
               label.text = [NSString stringWithFormat:@"Welcome %@", name3];
             }
           completion:^(BOOL finished){
           }];
        }];
    }];

我可以知道如何重复这个动画序列吗?将 UIViewAnimationOptionRepeat 放在最外面的动画上没有帮助。

已编辑:感谢 Matt 的解决方案,代码更改为

   CABasicAnimation *animation1 = [CABasicAnimation animation];
   label.text = [NSString stringWithFormat:@"Welcome %@!!!", name];
   animation1.keyPath = @"transform.scale";
   animation1.fromValue = [NSNumber numberWithFloat:0];
   animation1.toValue = [NSNumber numberWithFloat:1.0];
   animation1.duration = 2;


   CABasicAnimation *animation2 = [CABasicAnimation animation];
   UIFont *font=[UIFont fontWithName:@"Arial-BoldMT" size:120.0];
   int length = (int)[NSString stringWithFormat:@"%d", balance].length;
   NSString *pointString = [NSString stringWithFormat:@"welcome %@", name2];
   label.text = pointString;
   animation2.keyPath = @"transform.scale";
   animation2.fromValue = [NSNumber numberWithFloat:0];
   animation2.toValue = [NSNumber numberWithFloat:1.0];
   animation2.duration = 2;
   animation2.beginTime = animation1.duration - 0.1;

   CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
   [group setAnimations:[NSArray arrayWithObjects:animation1, animation2,nil]];
   group.duration = animation1.duration + animation2.duration;
   [label.layer addAnimation:group forKey:@"basic"];

我可以知道如何为不同的动画在 UIlabel 上设置不同的文本吗?下面的代码不起作用。本应在 animation2 开始时发生的文本更改发生在 animation1 开始之前,因此 animation1 显示了 animation2 的文本。

问候 锤子

最佳答案

问题是您正在尝试处理 View 动画,这是 Core Animation 的一个方便的前端 — 直到它不是。如果您直接在 Core Animation 级别编写分组动画,将会容易。这样一来,您就有了一个完整的“电影”,可以连续播放三个动画,并且可以轻松地重复(它只是重复整个“电影”)。

关于IOS动画,重复序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26345763/

相关文章:

iOS Swift PDFKit Widget 子类型按钮边框

ios - CATransaction 和 CAAnimation 有什么区别?

ios - 为什么当我为我的 CABasicAnimation 设置一个较低的持续时间值时它会跳转?

objective-c - 在 IKImageBrowserCell 中为 CALayer 设置动画

ios - 使用 NSValue 包装一个 C 指针

ios - Firebase 身份验证在应用程序删除过程中是否持续存在?

ios - 使用 UIPinchGestureRecognizer 缩放图层

ios - 在 iOS 上绘制动态角度(锥形)渐变的最快方法?

ios - 延迟激活 uitableviewcell 内的 uislider 的时间

ios - 多行 UINavigationBar