代码之家  ›  专栏  ›  技术社区  ›  rustyshelf

如何暂停UIImageView动画

  •  3
  • rustyshelf  · 技术社区  · 17 年前

    我有一个正在使用UIImageView显示的动画:

    imageView.animationImages = myImages;
    imageView.animationDuration = 3;
    [imageView startAnimating];
    

    我尝试将持续时间设置为一个更大的数字,但这也会导致所有图像消失。必须有一个真正基本的方法来做到这一点?

    6 回复  |  直到 13 年前
        1
  •  18
  •   mazniak    17 年前

    此代码将动画对象暂停在动画过程中的当前位置。如果记录其他变量,如时间、进度或任何需要的变量,则再次恢复动画应该是相当简单的。

    UIView *viewBeingAnimated = //your view that is being animated
    viewBeingAnimated.frame = [[viewBeingAnimated.layer presentationLayer] frame];
    [viewBeingAnimated.layer removeAllAnimations];
    //when user unpauses, create new animation from current position.
    
        2
  •  8
  •   Ashish Kakkad Roman Scher    11 年前

    嗯……因为似乎没人知道,我想这是不可能的。

    UIView ,带有 UIImageView subview NSTimer

        3
  •  3
  •   SW_Cali    14 年前

    @oddmeter只需稍加编辑:

        animatedView.animationImages = images; //images is your array
        [animatedView startAnimating];
    
    
        //Then when you need to pause;
    
    [animatedView stopAnimating]; //Important!!
        animatedView.image = [images objectAtIndex: 0];
    
        4
  •  2
  •   Ashish Kakkad Roman Scher    11 年前

    这应该可以做到: https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html

    CALayer 基于动画。

    加莱尔 方法论 UIImageView UIImage 基于阵列的动画。所需的代码非常短,您可以从这里获取: http://rssv2.blogspot.com/2011/04/animating-series-of-images-with-calayer.html

        5
  •  0
  •   Ashish Kakkad Roman Scher    11 年前

    animationImages 所有物执行此操作将在 UIImageView 它的动画停止了。

    UIImageView 并且有一个 NSMutableArray 对于图像,请执行以下操作:

    self.animationImages = images;
    //yes, I'm skipping the step to check and make sure you have at least one
    //element in your array
    self.image = [images objectAtIndex: 0];
    
        6
  •  -1
  •   Dan    17 年前

    也许你可以拍摄最后一张动画图像的截图并显示出来?