UILabel updating stops during scrolling UIScrollView

I had recently the same trouble and found the solution here: My custom UI elements....

In short: while your UIScrollView is scrolling, the NSTimer is not updated because the run loops run in a different mode (NSRunLoopCommonModes, mode used for tracking events).

The solution is adding your timer to the NSRunLoopModes just after creation:

NSTimer *elapsedTimeTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 
                                                             target:self 
                                                           selector:@selector(updateElapsedTimeLabel) 
                                                           userInfo:nil 
                                                            repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:elapsedTimeTimer 
                             forMode:NSRunLoopCommonModes];

(The code comes from the post linked above).


sergio's solution in Swift 5:

timer = Timer(timeInterval: 1, repeats: true) { [weak self] _ in
    self?.updateTimeLabel()
}
RunLoop.current.add(timer, forMode: .common)

I have seen similar behavior in combination with scrolling a UIScrollView. What probably happens is that the scrolling action completely blocks the main run loop, which is responsible for anything related to view updates. You are not doing anything wrong here, updates to the view hierarchy should be handled by the main loop so you can't just put your UILabel updating on a background thread (although I'd probably still try it to see what happens).

I haven't really done research into this issue, but I assume there is little you can do about it. I'll happily accept answers that prove me wrong!


sergio's solution in Swift 2:

self.updateTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "updateFunction", userInfo: nil, repeats: true)
NSRunLoop.currentRunLoop().addTimer(self.updateTimer, forMode: NSRunLoopCommonModes)