[英]IOS : UIScrollView and OpenGL
所以我有一個OpenGL(glView)視圖,它呈現一個我想要滾動的菜單。 我試圖避免重新發明UIScrollView,所以我在glView的頂部放置了一個scrollview。
問題是滾動滾動視圖會暫停渲染
這里討論了類似的問題。 當在iPhone上拖動UIScrollView時,OpenGL ES視圖中的動畫會凍結
問題是我不知道[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; 是指
我已經制作了一個新的CADisplayLink並試圖在沒有運氣的情況下完成上述操作
我試過在scrollViewDidScroll中調用render方法
我試過調用[self.view setNeedsDisplay];
我還發現調用timerLoop?
請有人幫幫我
所以,我找到了一個解決方案:)
創建CADisplayLink * _displayLink; 屬性(需要導入QuartzCore)
將您的滾動視圖置於頂部。
#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;
}
請參閱Apple WWDC 2012的會議223 。 從21:21開始,他們討論了將UIScrollView與OpenGL視圖集成。 有趣的部分從25:53開始。
主要的源代碼是由Burf2000編寫的,但是這個視頻解釋了為什么它正在工作,UIScrollView如何真正起作用以及它如何與OpenGL交互。 它還幫助我調試我的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.