Help me. I tried to make NSTimer with UIScrollView. but NSTimer stop during Scrolling on UIScroll View..
How can I keep work NSTimer during scrolling?
Help me. I tried to make NSTimer with UIScrollView. but NSTimer stop during Scrolling on UIScroll View..
How can I keep work NSTimer during scrolling?
I created a simple project with a scrollView and a label that is updated with an
NSTimer
. When creating the timer withscheduledTimerWithInterval
, the timer does not run when scrolling.The solution is to create the timer with
NSTimer:timeInterval:target:selector:userInfo:repeats
and then calladdTimer
onNSRunLoop.mainRunLoop()
withmode
NSRunLoopCommonModes
. This allows the timer to update while scrolling.Here it is running:
Here is my demo code:
Swift 3:
Swift 4, 5: