Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop animation after one repeat

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!

like image 426
user1492776 Avatar asked Dec 27 '22 22:12

user1492776


1 Answers

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];
like image 199
Pfitz Avatar answered Dec 31 '22 14:12

Pfitz