【问题标题】:iOS5 combine CGAffineTransform with animationImages?iOS5将CGAffineTransform与animationImages结合起来?
【发布时间】:2012-04-17 15:58:03
【问题描述】:

我对 iOS 动画很陌生,我想知道是否可以使用 CGAffineTransform 将两个图像之间的过渡与 UIImageView 的翻译动画结合起来?

换句话说,我想要在两张图像之间制作动画,然后我想应用同声翻译,以便整个内容在页面上移动,同时在两张图像之间来回移动。

我知道我可以应用 CGAffineTransformConcat 来组合两个 CGAffineTransform,例如 CGAffineTransformTranslate 和其他东西。但我没有看到允许我转换到另一个 UIImage 的 CGAffineTransform。

我知道在图像之间制作动画的唯一方法是将 UIImageView animationImages 数组与 startAnimating 结合使用。但是,我不知道如何将它与这样的翻译结合起来:

UIImageView* textView = [[UIImageView alloc] initWithFrame:bunnyImage.frame]; 

textView.animationImages = [NSArray arrayWithObjects:    
                            [UIImage imageNamed:@"bunnyclose.png"],
                            [UIImage imageNamed:@"bunnytalk.png"],
                            nil];

textView.animationDuration = 1.0;
textView.animationRepeatCount = 8;
[textView startAnimating];

[self.view addSubview:textView];    

有什么建议吗?

【问题讨论】:

    标签: animation ios5 uiimageview uiimage cgaffinetransform


    【解决方案1】:

    在回答我自己的问题时,"Creating Animated Transitions Between Views" 中讨论的块动画功能transitionFromView:toView:duration:options:completion 是我想出的最佳解决方案。我使用它在图像之间制作动画,它可以与块动画 animateWithDuration:delay:options:animations:completion: 使用 CGAffineTransformTranslate 或简单地通过更改 UIImageView 的 center 进行组合,如 Animations 中所述。

    修改我的原始代码块并添加我的翻译看起来像这样:

    UIImageView* bunny2View = [[UIImageView alloc] initWithFrame:bunny2Image.frame]; 
    
    
    [UIView 
     transitionFromView:bunny2Image 
     toView:bunny2View 
     duration:10.0 
     options:UIViewAnimationOptionShowHideTransitionViews 
     completion:^(BOOL finished) {
         [UIView 
          animateWithDuration:dur 
          animations:^(void) {
              CGPoint center = bunny2Image.center;
              center.y += deltay;
              bunny2Image.center = center;
              bunny2View.center = center;
          }
          completion:^(BOOL finished) {
    
              [UIView 
               transitionFromView:bunny2View 
               toView:bunny2Image 
               duration:10.0 
               options:UIViewAnimationOptionShowHideTransitionViews 
               completion:nil];
          }];
     }]; 
    

    仍在进行中,但这是我迄今为止的想法!

    【讨论】:

      猜你喜欢
      • 2021-09-28
      • 2019-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多