3 回答
![?](http://img1.sycdn.imooc.com/5333a207000118af02200220-100-100.jpg)
TA贡献2021条经验 获得超8个赞
我的简单解决方案是在运行循环处于跟踪模式时将渲染速率减半。我的所有UIScrollView现在都能顺利运行。
这是代码片段:
- (void) drawView: (CADisplayLink*) displayLink
{
if (displayLink != nil)
{
self.tickCounter++;
if(( [[ NSRunLoop currentRunLoop ] currentMode ] == UITrackingRunLoopMode ) && ( self.tickCounter & 1 ))
{
return;
}
/*** Rendering code goes here ***/
}
}
![?](http://img1.sycdn.imooc.com/5458631e0001ffd402200220-100-100.jpg)
TA贡献2039条经验 获得超7个赞
以下帖子的答案对我来说非常有效(它看起来与Till的答案非常相似):
UIScrollView暂停NSTimer直到滚动完成
总结一下:当出现UIScrollView时禁用CADisplayLink或GLKViewController渲染循环,并启动NSTimer以所需的帧速率执行更新/渲染循环。从视图层次结构中关闭/删除UIScrollView时,重新启用displayLink / GLKViewController循环。
在GLKViewController子类中,我使用以下代码
出现在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;
简单有效。我不确定这是否会导致某种类型的工件/撕裂,因为渲染与屏幕刷新分离,但在我们的案例中使用带有NSRunLoopCommonModes的CADisplayLink完全打破了UIScrollView。使用NSTimer对我们的应用程序看起来很好,绝对比没有渲染好很多。
- 3 回答
- 0 关注
- 670 浏览
添加回答
举报