I'm trying to freeze the last frame of an animation. The following code used to work, however after an update to iOS it no longer works. How can I write this code so that the last image stays on the screen?
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"];
I spend 40 my minutes to resolve your problem, and it was just so simple:
There are two way you can achieve what you want:
- Set the image you want on your screen as
default
image.
or just do this,
//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];
And guess what it'll start working, as I have tested it. :)
[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;
}
This is the example to show the image jumping i thick this may help u
Your code looks fine to me, except when I do it, I usually set the .image
property of the UIImageView
BEFORE I tell the UIImageView
to start animating. Also, add [UIImage imageNamed:@"watermelondrop16.png"]
to the end of your .animationImages
array. Maybe that will fix your problem. Hope that Helps!