Loading images after viewDidLoad
I have a view that loads over 100 images onto the screen during viewDidLoad like so:
cover = [[UIImageView alloc] initWithImage:[UIImage imageNamed:currentQuestion.image]];
cover.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:currentQuestion.image ofType:@"jpg"]];
cover.contentMode = UIViewContentModeScaleAspectFit;
cover.transform = CGAffineTransformMakeScale(0.1, 0.1);
cover.frame = CGRectMake(30, (current*70), 100, 100);
[scrollView2 addSubview:cover];
This is taking a bit of time to load (5+ seconds) and I remember learning that you should only load what you need on the screen so I would prefer to load the first 10 images, allow the view to load, and then add the remaining images in some other function since they are initially off-screen until the user scrolls down. Where开发者_如何学JAVA is the best place to do this? Do I just call another function in viewDidLoad like [self loadTheRest]; or [self performSelector:@selector(loadTheRest) withObject:nil afterDelay:0.3f]; ?
Thanks in advance for your help!
You could implement the UIScrollViewDelegate's scrollViewDidScroll:
method such that when a user scrolls to a new location, you load the images that would be visible.
See the UIScrollViewDelegate protocol reference for more information.
.h
UIScrollView* scrollView;
@property (nonatomic,retain) IBOutlet UIScrollView* scrollView;
.m
- (void)viewDidLoad {
scrollView.contentSize = self.view.frame.size;
}
精彩评论