我尝试解决问题几周,但我找不到答案。 我试着让动画结束时最后一帧冻结。
这是我的动画代码:
-(IBAction)play {
image.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"],nil];
[image setAnimationRepeatCount: 1];
image.animationDuration = 0.5;
[image startAnimating];
}
-(IBAction)stop{
[image stopAnimating];
}
当我按下按钮播放时,动画运行,当我按下按钮停止时,动画停止并消除图像。
我喜欢这样做而没有停止按钮,当动画结束时,最后一帧是可见的。
感谢您的帮助。
答案 0 :(得分:0)
我不知道这是否是最简单的方法,但它确实有效。你在这里:
- (IBAction)stop {
CGSize screenSize = [[UIScreen mainScreen] applicationFrame].size;
CGContextRef context = CGBitmapContextCreate(nil, screenSize.width, screenSize.height, 8, 4 * (int)screenSize.width, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);
CGBitmapContextCreateImage(context);
CGContextTranslateCTM(context, 0.0, screenSize.height);
CGContextScaleCTM(context, 1.0, -1.0);
[(CALayer*)self.layer renderInContext:context];
CGImageRef cgImage = CGBitmapContextCreateImage(context);
UIImage *lastFrame = [[UIImage alloc] initWithCGImage:cgImage];
CGImageRelease(cgImage);
CGContextRelease(context);
image.image = lastFrame;
[lastFrame release];
}
答案 1 :(得分:0)
如果你这样做会怎样:
-(IBAction)stop {
[image stopAnimating];
image.image = [image.animationImages objectAtIndex:12]; //or 0 to jump to the first image
}
为我工作:)