Search code examples
uinavigationcontrolleruiscrollviewglkitcadisplaylink

IOS : CADisplay / UIScrollview and Navigation Controller


So I have managed to get my lovely GLKit 3D menu working with a UIScrollview and life is good until I push to another view controller and come back.

So completely smooth movement, move to next controller and come back. UIScrollview does not bounce or flow nicely?

CADisplay Link is init and nil'd every time the scrollview moves and stops and this seems to work fine up until I push to another controller and come back.

Randomly if I click on a item which causes the scrollview to move and fire off all the code, it then kicks back in to life. sadly if I try to fire this off on the view did appear it does not do the same thing.

- (void)startDisplayLinkIfNeeded
{
    if (!self.displayLink) 
    {
        self.displayLink = [CADisplayLink displayLinkWithTarget:self.view selector:@selector(display)];
        [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    }
}

- (void)stopDisplayLink
{
    if (self.displayLink)
    {
         [self.displayLink removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];

        [self.displayLink invalidate];
        self.displayLink = nil;
    }
}

Solution

  • So, after a whole day of trying to work out this issue, it comes down to

    self.preferredFramesPerSecond = 60`
    

    If I dynamically change this to around 15 to 20 depending on what I do, the whole problem goes away.