LaVOZs

The World’s Largest Online Community for Developers

'; ios - How to Preload a page in UIpage view controller swift with local GIFs stored in project - LavOzs.Com

I'm trying to use GIF in my Image View using extension of UIImageView. I have 4 pages in a Page View Controller with 2 gifs each page. When i swipe right it shows some lag after 1 page. e.g. from the first page to the second page, it swiped smoothly while on from second to third it shows some lag while loading gifs. same coming back on second screen from third it moves smoothly but when i swipe again it shows a little lag. so basically it stores two pages in memory. the page you're coming from and the current page. if you swipe back to the page where from you coming it moves smoothly on the next move is another direction which is not loaded before it shows lag.

1) I have tried to load content in viewDidAppear(). but that was not good enough for my problem. by doing this movement becomes smooth but content loads after delay.

2) I tried to initiate all view controllers in UIPageViewController() view did load. but it did not work out.

func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
    var index = (viewController as! OnBoardingController).index
    index += 1
    return contentViewController(at : index)
}


func contentViewController(at index : Int) -> OnBoardingController? {
    if index < 0  || index >= headings.count {
        return nil
    }
    else {

        let board = UIStoryboard(name: "OnBoardingStoryBoard", bundle: nil)
        if let controller = board.instantiateViewController(withIdentifier: "OnBoardingController") as? OnBoardingController {
            controller.heading = self.headings[index]
            controller.details = self.subHeadings[index]
            controller.imageName = self.imageNames[index]
            controller.imageNameSecond = self.imagesnamesecond[index]
            controller.index = index
            return controller
        }
    }
    return nil
}

I want to increase the limit of preloaded pages in PageViewController. or if i could load pages in a separate section.

Related
UIPageViewController Gesture recognizers
In ios6, setting your pageViewController's gestureRecognizers delegate to a viewController causes a crash
jump to perticular viewcontroller in UIPageViewController
Laod a viewcontroller at perticular index from pagerviewcontroller
IOS - How to create a UIPageViewController with multiple ViewController from different XIB files
UIPageViewControllerDataSource calls viewControllerAfterViewController twice the first time running
make image view full screen in view controller/page view controller (swift)
Swift 3 embed button in page view controller
How to tracking index of pageViewController when swipe too fast or swipe to left and right continuously very fast