viewDidLoad之后加载图像

发布于 2024-10-26 06:34:14 字数 761 浏览 4 评论 0原文

我有一个视图在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是暖光i 2024-11-02 06:34:14

您可以实现 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.

纸伞微斜 2024-11-02 06:34:14

.h.m

UIScrollView* scrollView;
@property (nonatomic,retain)  IBOutlet UIScrollView* scrollView;

- (void)viewDidLoad {
    scrollView.contentSize = self.view.frame.size;
}

.h

UIScrollView* scrollView;
@property (nonatomic,retain)  IBOutlet UIScrollView* scrollView;

.m

- (void)viewDidLoad {
    scrollView.contentSize = self.view.frame.size;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文