我使用像这样的数组动画一些图像
NSArray *weatherFrames = [NSArray array];
weatherFrames = [[NSArray alloc] initWithObjects:
[UIImage imageWithData:Data1],
[UIImage imageWithData:Data2],
[UIImage imageWithData:Data3],
[UIImage imageWithData:Data4],
[UIImage imageWithData:Data5],
nil];
weatherImage.animationImages = weatherFrames;
weatherImage.animationDuration = 10.00;
weatherImage.animationRepeatCount = 1;
[weatherImage release];
我希望能够做的是当有人触发呼叫时暂停动画(即来自IBAction)。这可能还是有更好的方法吗?
由于
答案 0 :(得分:0)
我从答案here复制了解决方案。
-(void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
要让CALayer传递给pauseLayer函数,您可以使用以下代码。
CALayer *player = ImageView.layer;
[self pauseLayer:player];