So I have a OpenGL(glView) view that is rendering a menu which I aim to scroll. I was trying to avoid reinventing the UIScrollView and so I have place a scrollview on top of the glView.
The issue is that scrolling the scrollview pauses the rendering
A similar issue was discussed here Animation in OpenGL ES view freezes when UIScrollView is dragged on iPhone
Problem is I have no idea what [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; refers to
I have made a new CADisplayLink and tried to do the above with no luck
I have tried calling the render method in the scrollViewDidScroll
I have tried calling [self.view setNeedsDisplay];
I also found a referring to calling the timerLoop?
Can anyone help me out please
So, I have found a solution :)
create a CADisplayLink *_displayLink; property (you need import QuartzCore)
Have your scrollview on top.
#pragma mark - scrollView Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//code for moving the object here
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self startDisplayLinkIfNeeded];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate) {
[self stopDisplayLink];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self stopDisplayLink];
}
#pragma mark Display Link
- (void)startDisplayLinkIfNeeded
{
if (!_displayLink) {
// do not change the method it calls as its part of the GLKView
_displayLink = [CADisplayLink displayLinkWithTarget:self.view selector:@selector(display)];
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode];
}
}
- (void)stopDisplayLink
{
[_displayLink invalidate];
_displayLink = nil;
}
Please refer to the session 223 of Apple WWDC 2012. Starting from 21:21 they talk about integrating UIScrollView with OpenGL view. The interesting part starts at 25:53.
The main source code was written by Burf2000, but this video explains WHY it's working, how UIScrollView really works and how it might interact with OpenGL. It also helped me debug my code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With