IOS UIPageViewController scroll delay on page transition

I have a UIPageViewController with multiple pages, and when scrolling through them, everything works fine. PageViewController automatically preloads adjacent pages of the current one to ensure smooth scrolling (I have UIPageViewControllerTransitionStyle.Scroll)

In addition, I can also go to a specific page by entering a number. The problem is when I jump to a specific page programmatically, the PageViewController doesn’t seem to preload the neighboring pages either, so when I start hitting the page I just jumped to there is a half second delay before the PageViewController loads the next ViewController so that he could be displayed.

I used this answer to navigate to the pages: https://stackoverflow.com/a/167449/

and passed it to Swift:

weak var pvcw = pvc
pvc.setViewControllers([page], direction: UIPageViewControllerNavigationDirection.Forward, animated: true) { finished in
   if let pvcs = pvcw {
        dispatch_async(dispatch_get_main_queue(), {
            pvcs.setViewControllers([page], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
        })
    }
}

My question is: how can I get the UIPageViewController to preload the adjacent pages of the page that I just jumped to, just like it happens automatically when scrolling?

PS: I have the same problem when starting the application. When I initialize my PageViewController and set the first visible page as follows:

pvc.setViewControllers([firstPage], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)

I also have this delay when I first view the second page. Any help is appreciated!

+4
source share

Source: https://habr.com/ru/post/1612209/


All Articles