ios – 暂停UIImageView动画

我正在做一个像这样的UI ImageView动画:

//////progressbar start
progressbar.animationImages = [NSArray arrayWithObjects:
                               [UIImage imageNamed:@"1.png"],
                               [UIImage imageNamed:@"2.png"],
                               [UIImage imageNamed:@"3.png"],
                               [UIImage imageNamed:@"4.png"],
                               [UIImage imageNamed:@"5.png"],
                               [UIImage imageNamed:@"6.png"],
                               [UIImage imageNamed:@"7.png"],
                               [UIImage imageNamed:@"8.png"],
                               [UIImage imageNamed:@"9.png"],
                               [UIImage imageNamed:@"10.png"],
                               [UIImage imageNamed:@"11.png"],
                               [UIImage imageNamed:@"12.png"],
                               [UIImage imageNamed:@"13.png"],
                               [UIImage imageNamed:@"14.png"],
                               [UIImage imageNamed:@"15.png"],
                               [UIImage imageNamed:@"16.png"],
                               [UIImage imageNamed:@"17.png"],
                               [UIImage imageNamed:@"18.png"],
                               [UIImage imageNamed:@"19.png"],
                               [UIImage imageNamed:@"20.png"],
                               [UIImage imageNamed:@"21.png"],
                               [UIImage imageNamed:@"22.png"],
                               [UIImage imageNamed:@"23.png"],
                               [UIImage imageNamed:@"24.png"],
                               [UIImage imageNamed:@"25.png"],
                               [UIImage imageNamed:@"26.png"],
                               [UIImage imageNamed:@"27.png"],
                               [UIImage imageNamed:@"28.png"],
                               [UIImage imageNamed:@"29.png"],
                               [UIImage imageNamed:@"30.png"],
                               [UIImage imageNamed:@"31.png"],
                               [UIImage imageNamed:@"32.png"],
                               [UIImage imageNamed:@"33.png"],
                               [UIImage imageNamed:@"34.png"],
                               [UIImage imageNamed:@"35.png"],
                               [UIImage imageNamed:@"36.png"],
                               [UIImage imageNamed:@"37.png"],
                               [UIImage imageNamed:@"38.png"],
                               [UIImage imageNamed:@"39.png"],
                               [UIImage imageNamed:@"40.png"],
                               [UIImage imageNamed:@"41.png"],
                               [UIImage imageNamed:@"42.png"], nil];
progressbar.animationDuration = 5.00;
progressbar.animationRepeatCount = 0;
[progressbar startAnimating];

现在我需要暂停它,这样一旦用户点击按钮,图像就不会生成动画并保留在当前图像上.

我把这个代码从网上拿下来暂停,

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.

这段代码会起作用吗?另外,我如何从当前图像中取消它?

我也尝试使用此代码,但它不起作用.

相反,您可以使用以下链接中的apple提供的代码来暂停和恢复动画.

http://developer.apple.com/library/ios/#qa/qa1673/_index.html

要使CALayer传递给pauseLayer函数,您可以使用以下代码.

CALayer *player = progressbar.layer;
[self pauseLayer:player];
相关文章
相关标签/搜索