To animate between images (not .gif) in a UIImageView like the example below
Original images
Result
The existing method in UIImageView
simply won’t work.
To get the result like this
MyViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| - (void)viewDidLoad { [super viewDidLoad];
[self animateImages]; }
- (void)animateImages { static int count = 0; NSArray *animationImages = @[[UIImage imageNamed:@"Image1"], [UIImage imageNamed:@"Image2"]]; UIImage *image = [animationImages objectAtIndex:(count % [animationImages count])]; [UIView transitionWithView:self.animationImageView duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.animationImageView.image = image; } completion:^(BOOL finished) { [self animateImages]; count++; }]; }
|
Reference: How to animate the change of image in an UIImageView?