iPhone SDK:延迟加载scrollView图片的问题
我的应用程序涉及一个滚动视图,其中包含用户通过修改后的 ELCImagePicker 选择的图像视图。所选择的图片通常是 5 MB 以上的高质量照片,并且用户通常会一次选择至少十几张图片。目前,我正在加载照片,如下所示:
-(void)loadViewWithPage: (int)page
{
if (page > 0 && page < [Album count]) {
[scrollView addSubview:[Album objectAtIndex:page]];
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)sender
{
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth) / pageWidth) + 1;
[self loadViewWithPage:page + 1];
}
其中相册是将照片存储为 imageView 的位置。
当用户不想破坏应用程序并一次滚动浏览照片时,这种方法非常有效,但当他/她尝试滚动整个选择时,这种方法就会失败。除非用户在每张照片后停下来,否则页面都是空白的。我尝试使用scrollViewDidScroll ala PageControl示例,但由于照片都很大,所以滞后非常明显。
有什么办法可以顺利加载照片吗?
My app involves a scrollView containing imageViews chosen by the user through a modified ELCImagePicker. The chosen pictures will typically be high quality photos at 5 MB+ and the user will usually choose at least a dozen pictures at a time. Currently, I am loading the photos as below:
-(void)loadViewWithPage: (int)page
{
if (page > 0 && page < [Album count]) {
[scrollView addSubview:[Album objectAtIndex:page]];
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)sender
{
CGFloat pageWidth = scrollView.frame.size.width;
int page = floor((scrollView.contentOffset.x - pageWidth) / pageWidth) + 1;
[self loadViewWithPage:page + 1];
}
Where Album is where the photos are stored as imageViews.
This works great when the user is not trying to break the app and scroll through the photos one at a time, but fails miserably when he/she tries to scroll through the entire selection. The pages are blank unless the user stops after each photo. I tried using scrollViewDidScroll ala PageControl sample, but since the photos are all huge the lag is very visible.
Is there any way of loading the photos smoothly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了类似的情况,并通过创建 NSOperation 的自定义子类来处理它,该子类将在单独的线程中加载图像,然后通过调用主线程上的方法来显示它们。
加载图像时我显示了一个 UIActivityView
希望有帮助。
I had a similar situation and dealt with it by creating a custom subclass of NSOperation which would load the images in a separate thread and then display them by calling a method on the main thread.
While the image was loading I displayed a UIActivityView
Hope that helps.
如果您使用
scrollViewDidEndDecelerating
它只会在滚动视图停止时触发。我会使用scrollViewDidScroll
来实现这一点。 (它也在他们的示例中使用)if you use
scrollViewDidEndDecelerating
it will only fire when the scrollview stops. I would usescrollViewDidScroll
for that. (it's also used in their examples)