viewDidLoad之后加载图像
我有一个视图在 viewDidLoad 期间将超过 100 个图像加载到屏幕上,如下所示:
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];
这需要一些时间来加载(5 秒以上),我记得我了解到您应该只在屏幕上加载您需要的内容,所以我更喜欢加载前 10 个图像,允许加载视图,然后在其他函数中添加剩余的图像,因为它们最初位于屏幕外,直到用户向下滚动。执行此操作的最佳地点在哪里?我是否只是在 viewDidLoad 中调用另一个函数,例如 [self loadTheRest];或 [self PerformSelector:@selector(loadTheRest) withObject:nil afterDelay:0.3f]; ?
预先感谢您的帮助!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以实现 UIScrollViewDelegate 的
scrollViewDidScroll:
方法,以便当用户滚动到新位置时,加载可见的图像。请参阅 UIScrollViewDelegate 协议参考更多信息。
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.m
.h
.m