Why does UIScrollView pause my CADisplayLink?

有些话、适合烂在心里 提交于 2019-11-30 17:40:43
rickster

You're not in NSDefaultRunLoopMode while scrolling a UIScrollView; you're in UITrackingRunLoopMode. So any timer scheduled only for the former won't fire in the latter. You can add your CADisplayLink to multiple run loop modes by calling addToRunLoop:forMode: repeatedly, or call it once with NSRunLoopCommonModes, which covers both modes.

They talked about this in detail, and other issues with integrating scroll views with GL, at WWDC 2012 in Session 223: "Enhancing User Experience with Scroll Views"; I recommend watching the video, as there's lots of other stuff in there that's likely relevant to your situation.


An example in (2016) Swift3...

let d = CADisplayLink(target: self, selector: #selector(ThisClassName.updateAlpha))
d.add(to: RunLoop.current, forMode: RunLoopMode.commonModes)


//and then, for example...
func updateAlpha() {
  let a = leader.layer.presentation()?.value(forKey: "opacity") as! CGFloat
  follower.alpha = a
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!