One way to avoid redrawing everything is to call setNeedsDisplayInRect:
instead of setNeedsDisplay:
, and passing only a rectangle containing the image that needs to be redrawn. Of course this means that your drawRect
can no longer ignore the rectangle passed in: go through the images, and check if an image overlaps with the rectangle being redrawn. If there is no overlap, skip the image and save some CPU time on a redraw.
Note that this is a very "manual" way of maintaining a view. Consider using some of the components that iOS provides for you, such as UICollectionView
, which lets you display lots of stuff on the screen with very little code.