Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollView pauses NSTimer until scrolling finishes

While a UIScrollView (or a derived class thereof) is scrolling, it seems like all the NSTimers that are running get paused until the scroll is finished.

Is there a way to get around this? Threads? A priority setting? Anything?

like image 389
mcccclean Avatar asked Mar 03 '09 03:03

mcccclean


2 Answers

An easy & simple to implement solution is to do:

NSTimer *timer = [NSTimer timerWithTimeInterval:...                                           target:...                                        selector:....                                        userInfo:...                                         repeats:...]; [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; 
like image 197
Kashif Hisam Avatar answered Oct 06 '22 15:10

Kashif Hisam


For anyone using Swift 3

timer = Timer.scheduledTimer(timeInterval: 0.1,                             target: self,                             selector: aSelector,                             userInfo: nil,                             repeats: true)   RunLoop.main.add(timer, forMode: RunLoopMode.commonModes) 
like image 43
Isaac Avatar answered Oct 06 '22 16:10

Isaac