Reputation: 280
i create an array of 2 images, animate then and everything work perfectly. but now i want the animation to stop after one repeat, i mean that the animation will start with the first image, move to second one and stop (and the second image will stay on my imageview). how can i do it? here is my code:
UIImage *mistakeOne = [UIImage imageNamed:@"Xmark.png"];
UIImage *mistakeOneB = [UIImage imageNamed:@"XmarkWhite.png"];
NSMutableArray *animation = [[NSMutableArray alloc] initWithObjects:mistakeOne, mistakeOneB , nil];
[mistakeNumberOne setAnimationImages:animation];
mistakeNumberOne.animationDuration = 5.0;
[mistakeNumberOne startAnimating]
thanks!
Upvotes: 4
Views: 3677
Reputation: 5909
Pfitz's answer is great for animating. However, for this is specific case where you have only two images and you only need to 'swap' between them its probably simpler to just change the image after a delay.
-(void)swapImage {
[mistakeNumberOne setImage:mistakeOneB];
}
then delay swapImage:
[self performSelector:@selector(swapImage) withObject:nil afterDelay:5.0];
hope this helps
Upvotes: 2
Reputation: 7344
Assuming mistakeNumberOne is a UIImageView
[mistakeNumberOne animationRepeatCount:1];
If you want to keep an image after the animation set the desired image in the UIImageview before the animation:
mistakeNumberOne.image = myDesiredImage;
After the animation it will show the image.
Putting it all together:
UIImage *mistakeOne = [UIImage imageNamed:@"Xmark.png"];
UIImage *mistakeOneB = [UIImage imageNamed:@"XmarkWhite.png"];
NSMutableArray *animation = [[NSMutableArray alloc] initWithObjects:mistakeOne, mistakeOneB , nil];
[mistakeNumberOne setAnimationImages:animation];
mistakeNumberOne.animationDuration = 5.0;
[mistakeNumberOne animationRepeatCount:1];
mistakeNumberOne.image = mistakeOneB;
[mistakeNumberOne startAnimating];
Upvotes: 8