Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Whether <code>CADisplayLink</code> fires during scrolls depends on the mode with which you add it to the run loop. Probably you have this, somewhere:</p> <pre><code>[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; </code></pre> <p>UIApplication adds a run loop mode, <code>UITrackingRunLoopMode</code>, for 'tracking in controls', which includes when a scrollview is scrolling. So at that point the runloop is switched out of the default mode and hence your display link (and also any timers, <code>NSURLConnections</code>, etc, added in the default mode) will fail to fire until default mode is restored.</p> <p>Quick fix: change your code to:</p> <pre><code>[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; </code></pre> <p>UITrackingRunLoopMode is considered one of the common modes.</p> <p>Spending too much time interrupting UIKit can lead to some very poor control responsiveness, so you need to be careful. It'd be to diverge from the topic massively, but although OpenGL is modal and therefore not particularly threading friendly, you can use an EAGLSharegroup to do rendering on a separate thread and then push it onto the main thread.</p> <hr> <p>An example in (2016) Swift3...</p> <pre><code>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 } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload