How to animate the change of image in an UIImageView?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Changing the image of a UIImageView instantly works, but it often looks abrupt in a polished iOS interface. The usual solution is to animate the transition with a cross-dissolve, a Core Animation transition, or a frame-based image animation depending on whether you are swapping one image, sliding between states, or playing a sequence.
Use a Cross-Dissolve for Ordinary Image Replacement
For most UI work, the simplest and best-looking solution is a transition animation around the image assignment.
This is the normal answer when the requirement is "replace one image with another smoothly."
Use It in a View Controller
A small example makes the pattern clearer.
The return value of the button action is not important here. The key is that the image property changes inside the transition block.
Use CATransition for More Control
If you want a different effect such as push or reveal, Core Animation gives you more options.
This is useful when the image change represents navigation or directional movement rather than a neutral fade.
Use animationImages for Frame Sequences
If you are not switching from one static image to another, but instead want to play a short sequence, UIImageView has built-in support for frame animation.
This is a different tool from transition-based swapping. Use it when the goal is an animated sequence, not a one-time replacement.
Handle Remote Images Carefully
If the image comes from the network, the transition should happen after the image data is ready, not while the fetch is still running. Otherwise the UI may fade into placeholder states or flicker as images arrive late.
A common pattern is:
- fetch or decode the image off the main thread
- return to the main thread
- perform the transition with the final image
That keeps the animation tied to a real visual change rather than to asynchronous uncertainty.
Keep the Animation Intentional
Not every image change needs animation. Small interface icons that change frequently can feel sluggish if every update is animated. On the other hand, hero images, avatars, and gallery content often benefit from a short fade.
A good rule is to animate when the change is noticeable enough that an abrupt swap would feel jarring. Use a short duration, usually around a quarter second to a third of a second, unless the design specifically calls for something more dramatic.
Common Pitfalls
- Setting the image outside the animation block and expecting a transition.
- Using heavy transitions for tiny images that change frequently.
- Starting the animation before a remote image is actually loaded.
- Confusing one-time transitions with frame-based image sequences.
- Performing UIKit updates off the main thread.
Summary
- For most
UIImageViewswaps, useUIView.transitionwith.transitionCrossDissolve. - Use
CATransitionwhen you need more directional or custom transition effects. - Use
animationImageswhen the requirement is a frame sequence rather than a simple replacement. - Trigger the animation only after the real image is ready.
- Keep image animations short and intentional so they improve the UI instead of distracting from it.

