Preloading pages of UIPageViewController

拈花ヽ惹草 提交于 2019-12-03 18:28:21

问题


I can't find a good solution to having the UIPageViewController preload the surrounding ViewControllers.

Right now what happens is when the user starts to turn the page, nothing happens, the code calls

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
       viewControllerAfterViewController:(UIViewController *)viewController

and once its loaded thennnn it shows the animation. This takes too long and is not smooth.

Anyone have a solution?


回答1:


Create a mutable container and when you show the first view, create the two viewController that would be needed if the user pages, once you have the viewController object ask it for its view (to get it to load the nib and call the controller's "viewDidLoad:" method. You need to figure out a system on identifying the viewControlers so you can retrieve the viewController you need). You might be able to do the heavy lifting here in a block on a dispatch_queue.

From then on, when the user pages, you look first in the container for the viewController, and if not found, you have to do it in real time.

You probably want to use a dispatch_group so that you can wait on it for pending blocks to finish before paging.

Everytime the user pages, you will look and see if the pages surrounding that page are in the container or not. You could also pre-fetch more viewControllers - like two forward two reverse at each page shown.



来源:https://stackoverflow.com/questions/11659604/preloading-pages-of-uipageviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!