I want to preload images sot that when I add their UIImageView to my currentView, the PNG are already in memory, loaded, inflated etc.
As you can see from this time profiling, the images are loaded when they are displayed:
In the same time, I'm already preloading these images before. Just when I load that view, I thoroughly create all images and image views for these animations using that code:
- (UIImageView*)createAnimationForReel:(NSString*)reel ofType:(NSString*)type usingFrames:(NSInteger)frames{
UIImageView *imageView = [[UIImageView alloc] init];
NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:frames];
for (int i=0;i<frames;i++){
NSString *image;
if(i<10){
image = [NSString stringWithFormat:@"%@_0%i", reel, i];
} else {
image = [NSString stringWithFormat:@"%@_%i", reel, i];
}
NSString *path = [[NSBundle mainBundle] pathForResource:image ofType:@"png" inDirectory:type];
UIImage *anImage = [[UIImage alloc] initWithContentsOfFile:path];
[imageArray addObject:anImage];
}
imageView.animationImages = [NSArray arrayWithArray:imageArray];
imageView.animationDuration = 2.0;
return imageView;
}
And when I read the documentation it says: "This method loads the image data into memory and marks it as purgeable. If the data is purged and needs to be reloaded, the image object loads that data again from the specified path." talking about initWithContentOfFile. So my image "should" be loaded.
But no.
Surely something is missing in my reflection. But what?