Reputation: 19905
I have a couple of UIViews with UIImageViews on them. When I display a view the first time, there is a noticeable lag (0.5 second or so) before it is shown. When shown again everything works.
I have managed to work around this by adding all views and then removing them. Like this:
[self performSelectorOnMainThread:@selector(addAndRemoveAllViews)
withObject:nil
waitUntilDone:NO];
The function loops over all views and [addSubview:view]
followed by [view removeFromSuperview]
. This seems to trigger the images to load while not being shown.
Questions:
Update:
Images are created from NSData
like this:
[[UIImageView alloc] initWithImage:[UIImage imageWithData:rawData]];
Upvotes: 2
Views: 382
Reputation: 75058
It seems very likely the image is larger than the image view. If possible shrink it down to the size the image view needs.
The initial delay is loading the image from storage, after that you are using a cached version which is why it is faster.
Upvotes: 2