3 回答

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個贊
我的簡單解決方案是在運(yùn)行循環(huán)處于跟蹤模式時將渲染速率減半。我的所有UIScrollView現(xiàn)在都能順利運(yùn)行。
這是代碼片段:
- (void) drawView: (CADisplayLink*) displayLink
{
if (displayLink != nil)
{
self.tickCounter++;
if(( [[ NSRunLoop currentRunLoop ] currentMode ] == UITrackingRunLoopMode ) && ( self.tickCounter & 1 ))
{
return;
}
/*** Rendering code goes here ***/
}
}

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個贊
以下帖子的答案對我來說非常有效(它看起來與Till的答案非常相似):
UIScrollView暫停NSTimer直到滾動完成
總結(jié)一下:當(dāng)出現(xiàn)UIScrollView時禁用CADisplayLink或GLKViewController渲染循環(huán),并啟動NSTimer以所需的幀速率執(zhí)行更新/渲染循環(huán)。從視圖層次結(jié)構(gòu)中關(guān)閉/刪除UIScrollView時,重新啟用displayLink / GLKViewController循環(huán)。
在GLKViewController子類中,我使用以下代碼
出現(xiàn)在UIScrollView上:
// disable GLKViewController update/render loop, it will be interrupted
// by the UIScrollView of the MPMediaPicker
self.paused = YES;
updateAndRenderTimer = [NSTimer timerWithTimeInterval:1.0f/60.0f target:self selector:@selector(updateAndRender) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:updateAndRenderTimer forMode:NSRunLoopCommonModes];
解雇UIScrollView:
// enable the GLKViewController update/render loop and cancel our own.
// UIScrollView wont interrupt us anymore
self.paused = NO;
[updateAndRenderTimer invalidate];
updateAndRenderTimer = nil;
簡單有效。我不確定這是否會導(dǎo)致某種類型的工件/撕裂,因?yàn)殇秩九c屏幕刷新分離,但在我們的案例中使用帶有NSRunLoopCommonModes的CADisplayLink完全打破了UIScrollView。使用NSTimer對我們的應(yīng)用程序看起來很好,絕對比沒有渲染好很多。
- 3 回答
- 0 關(guān)注
- 686 瀏覽
添加回答
舉報(bào)