To animate between images (not .gif) in a UIImageView like the example below

Original images

First image

Second image

Result

Animate between 2 images

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];

// make the first call
[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 // animation duration
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.animationImageView.image = image; // change to other image
} completion:^(BOOL finished) {
[self animateImages]; // once finished, repeat again
count++; // this is to keep the reference of which image should be loaded next
}];
}

Reference: How to animate the change of image in an UIImageView?