You could make a category for the UIImage class for preloading your image in a background thread before you provide it to the image property of your UIImageView:
h:
#import <Foundation/Foundation.h>
@interface UIImage (preloadedImage)
- (UIImage *) preloadedImage;
@end
m:
#import "UIImage+preloadedImage.h"
@implementation UIImage (preloadedImage)
- (UIImage *) preloadedImage {
CGImageRef image = self.CGImage;
// make a bitmap context of a suitable size to draw to, forcing decode
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef imageContext = CGBitmapContextCreate(NULL, width, height, 8, width * 4, colourSpace,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
CGColorSpaceRelease(colourSpace);
// draw the image to the context, release it
CGContextDrawImage(imageContext, CGRectMake(0, 0, width, height), image);
// now get an image ref from the context
CGImageRef outputImage = CGBitmapContextCreateImage(imageContext);
UIImage *cachedImage = [UIImage imageWithCGImage:outputImage];
// clean up
CGImageRelease(outputImage);
CGContextRelease(imageContext);
return cachedImage;
}
@end
make the call of the preloadedImage on a background thread then and set the result on the main thread.