Speed ​​up UIPageViewController

I have a UIPageViewController with multiple pages. Each page represents the same view controller, but the page number is tracked and the correct PDF page is displayed. The problem is that every PDF page has to be loaded and drawn before the curling effect (you swipe the screen and nothing happens until it loads). Any ideas on how to speed this up or preload the next page? Thanks for your help.

+3


source to share


1 answer


I have a similar problem in the application I am using now. My solution was to keep a reference to the loaded previous and next controllers as properties of my root view controller and then just load the view from there. I am not using PageViewController because the client insisted they had to look like FlipBoard ... so I also cache the resulting GLTexture. It should work in a similar way, just save the next and previous page when the current one is loaded and pass this controller to your "loadNextPage" or any other method.

EDIT: Here's an example (which I simplified) from my project

First Load (NH is a prefix for my program, so you'll need to replace your own classes):

NHViewController *child = [NHViewController loadPageNum:actualNum];
[self.view addSubview:child.view];
self.curController = child;
child.delegate = self;
[self initializePages:NHPageLoadBoth];

      

Subsequent downloads (page flipping):



    NHPageLoadSettings pageToLoad = NHPageLoadNext;
    if(direction == NHPageDirectionNextPage)
    {
        self.prevController = self.curController;
        self.curController = self.nextController;
        self.nextController = nil;
    }
    else
    {
        self.nextController = self.curController;
        self.curController = self.prevController;
        self.prevController = nil;
        pageToLoad = NHPageLoadPrev;
    }

    UIView *nextView = self.curController.view;
    [self.view addSubview:nextView];
    [mCurView removeFromSuperview];
    mCurView = nextView;

    [self initializePages:pageToLoad];

      

Initialize pages:

- (void)initializePages:(NHPageLoadSettings)pagesToLoad
{
    if(pagesToLoad & NHPageLoadNext)
    {
        NSUInteger nextPageNum = [self.curController.pageNum unsignedIntegerValue]+1;
        self.nextController = [NHViewController loadPageNum:nextPageNum];
    }
    if(pagesToLoad & NHPageLoadPrev)
    {
        NSUInteger prevPageNum = [self.curController.pageNum unsignedIntegerValue]-1;
        self.prevController = [NHViewController loadPageNum:prevPageNum];
    }
}

      

This way you will always have adjacent pages. Then, instead of instantiating it in the method that fetches the next or previous page in the UIPageViewController, just pass self.nextController or self.prevController.

+6


source







All Articles