我正在尝试冻结动画的最后一帧。以下代码用于工作,但是在更新到iOS之后它不再有效。如何编写此代码以便最后一个图像保留在屏幕上?
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"watermelondrop2.png"],
[UIImage imageNamed:@"watermelondrop4.png"],
[UIImage imageNamed:@"watermelondrop6.png"],
[UIImage imageNamed:@"watermelondrop8.png"],
[UIImage imageNamed:@"watermelondrop10.png"],
[UIImage imageNamed:@"watermelondrop12.png"],
[UIImage imageNamed:@"watermelondrop14.png"],
[UIImage imageNamed:@"watermelondrop15.png"], nil];
animation.animationDuration = .8;
animation.animationRepeatCount = 1;
[animation startAnimating];
[self playwatermelondropsound];
[self.view addSubview:animation];
animation.image = [UIImage imageNamed:@"watermelondrop16.png"];
答案 0 :(得分:7)
我花了40分钟来解决你的问题,这很简单:
有两种方法可以达到你想要的效果:
default
图像。或者只是这样做,
//make your last line to first line.
animation.image = [UIImage imageNamed:@"watermelondrop16.png"];
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"watermelondrop2.png"],
[UIImage imageNamed:@"watermelondrop4.png"],
[UIImage imageNamed:@"watermelondrop6.png"],
[UIImage imageNamed:@"watermelondrop8.png"],
[UIImage imageNamed:@"watermelondrop10.png"],
[UIImage imageNamed:@"watermelondrop12.png"],
[UIImage imageNamed:@"watermelondrop14.png"],
[UIImage imageNamed:@"watermelondrop15.png"], nil];
animation.animationDuration = .8;
animation.animationRepeatCount = 1;
[animation startAnimating];
[self playwatermelondropsound];
[self.view addSubview:animation];
并猜测它会开始工作,因为我已经测试过了。 :)
答案 1 :(得分:2)
[self cleanStance];
NSArray *imageArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"jump1.png"],
[UIImage imageNamed:@"jump2.png"],
nil];
self.player.animationImages = imageArray;
self.player.animationDuration = 0.3;
//self.player.contentMode = UIViewContentModeBottomLeft;
[self.view addSubview:self.player];
[self.player startAnimating];
- (void)cleanStance {
[self.player setImage:nil];
self.player.animationImages = nil;
}
这是显示图像跳跃的示例,这可能有助于你
答案 2 :(得分:0)
您的代码对我来说很好,除非我这样做,我通常会设置.image
之前的UIImageView
属性我告诉UIImageView
开始制作动画。另外,将[UIImage imageNamed:@"watermelondrop16.png"]
添加到.animationImages
数组的末尾。也许那会解决你的问题。希望有帮助!