UIImageView animation frame by frame

I have an idea on how to add an animated UIImageView using the frame by frame method. But my question about how to animate UIImageView is ALREADY added to the view manager storyboard as an IBOutlet UIImageView.

what will change in this world of code ?!

NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"bookmark1.png"], [UIImage imageNamed:@"bookmark2.png"], [UIImage imageNamed:@"bookmark3.png"], [UIImage imageNamed:@"bookmark4.png"], [UIImage imageNamed:@"bookmark5.png"],nil]; myAnimatedView = [UIImageView alloc]; [myAnimatedView initWithFrame:CGRectMake(0, 0, 131, 125)]; myAnimatedView.animationImages = myImages; myAnimatedView.animationDuration = 0.25; myAnimatedView.animationRepeatCount = 1; [myAnimatedView startAnimating]; [self.navigationController.view addSubview:myAnimatedView]; 

I want to animate this image like on my viewController

http://imageshack.us/a/img717/3051/bookmarkl.gif

+4
source share
2 answers

It is even easier. First add the .h file:

 @property (nonatomic, retain) IBOutlet UIImageView *iV; 

After that, plug this outlet into the actual UIImageView on your storyboard. Change your code:

 iV.animationImages = myImages; iV.animationDuration = 0.25; iV.animationRepeatCount = 1; [iV startAnimating]; 

And it's all. Hope this helps

ps And yes, don't forget iV = nil; in - (void) viewDidUnload

UPD: added

 [self performSelector:@selector(animationDone) withObject:nil afterDelay:0.25]; 

After starting, make a call and obviously add the animationDone method:

 - (void)animationDone { [iV stopAnimating]; [iV setImage:[UIImage imageNamed:@"bookmark5.png"]]; } 
+5
source

Well, it will be almost the same. You do not need to select the [[UIImageView alloc] init] image, and you do not need to add it to the viewController. The rest is the same.

0
source

Source: https://habr.com/ru/post/1436086/


All Articles