Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView pauses NSTimer while scrolling

I have a UIScrollView that has a series of labels which are rapidly updating numbers (every .06 seconds). While the scroll view is moving, however, the NSTimer is paused and does not continue until after the scrolling and the elastic animation have finished.

How can I avoid this and have the NSTimer run regardless of the state of the scroll view?

like image 407
Peter Kazazes Avatar asked Aug 14 '11 20:08

Peter Kazazes


2 Answers

An easy way to fix this is adding your NSTimer to the mainRunLoop.

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

To remove a timer from all run loop modes on which it is installed, send an invalidate message to the timer.

like image 56
Iñigo Beitia Avatar answered Oct 18 '22 23:10

Iñigo Beitia


for swift:

NSRunLoop.mainRunLoop().addTimer(timer, forMode: NSRunLoopCommonModes)
like image 44
Matt Wyeth Avatar answered Oct 18 '22 23:10

Matt Wyeth