我如何延迟加载 100+ UIScrollView 中启用分页的页面?
我正在创建一个类似漫画书的应用程序。我正在使用启用分页的 UIScrollView 来显示高分辨率全屏图像(该应用程序的工作方式与 Photos.app 类似,但禁用了缩放)。最终产品将有近 200 张图像需要用户翻阅。如何为如此大量的页面设置 UIScrollView?
只需使用直接的 UIViews 就可以很容易地实现这一点,但是 UIScrollView 的“感觉”在弹跳等方面要好得多,我认为它为我的应用程序增加了更多价值。我应该如何使其发挥作用?
I'm creating a comicbook-like application. I'm using a UIScrollView with paging enabled to display the hi-res full-screen images (the app works similar to Photos.app but with zooming disabled). The final product will have nearly 200 images that need to be paged through by the user. How do I go about setting up the UIScrollView for such a large number of pages?
This would be fairly easy to accomplish with just straight UIViews, but the "feel" of the UIScrollView is just so much nicer with the bounce, etc that I think it adds more value to my app. How should I approach making it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 Apple 的 PageControl 示例代码。它向您展示了如何使用 UIScrollView 和 UIPageControl 循环浏览视图控制器(就像照片应用程序一样)。每个页面仅根据需要加载。
基本上,为了实现延迟加载,您需要从一组空视图控制器开始。然后,当您滚动时,您仅加载当前页面的视图控制器以及上一个和下一个页面的视图控制器,以便滚动显得平滑。只需查看示例项目即可,它相当简短且易于理解。它至少应该让你开始。 UIScrollView 将告诉适当的控制器何时加载自身。然后控制器负责加载其内容(在您的情况下是图像)。
祝你好运。
Checkout Apple's sample code for PageControl. It shows you how to use a UIScrollView and UIPageControl to cycle through view controllers (just like the photo app). Each page is loaded only as needed.
Basically to achieve lazy loading you start off with an array of empty view controllers. Then as you scroll you load only the current page's view controller as well as the previous and next ones so that scrolling appears smooth. Just look over the sample project, it's fairly short and simple to follow. It should at least get you started. The UIScrollView will tell the appropriate controller when to load itself. It is then the controller's responsibility to load its content (in your case an image).
Good luck.