【问题标题】:Loading images after viewDidLoad在 viewDidLoad 之后加载图像
【发布时间】:2011-03-23 16:05:47
【问题描述】:

我有一个视图,它在 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]; ?

提前感谢您的帮助!

【问题讨论】:

    标签: iphone image viewdidload


    【解决方案1】:

    您可以实现 UIScrollViewDelegate 的 scrollViewDidScroll: 方法,这样当用户滚动到新位置时,您会加载可见的图像。

    请参阅UIScrollViewDelegate protocol reference 了解更多信息。

    【讨论】:

      【解决方案2】:

      .h

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

      .m

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-11
        • 2018-04-29
        • 1970-01-01
        • 2018-11-17
        相关资源
        最近更新 更多