You need to add a timer to another RunLoopMode. By default, a timer is added to NSDefaultRunLoopMode. This means that the timer only runs when the application launch loop is in NSDefaultRunLoopMode.
Now, when the user touches the screen (for example, to scroll through the UIScrollView), the launch cycle mode switches to NSEventTrackingRunLoopMode. And now that the loop loop is no longer in NSDefaultRunMode, the timer will not execute. The ugly effect is that the timer is locked whenever the user touches the screen. And this may be the time when the user scrolls, as the timer locks until the scroll stops completely. And when the user continues to scroll, the timer locks again.
Fortunately, the solution to this problem is quite simple: you can add your timer to another NSRunLoopMode. When you add a timer to NSRunLoopCommonModes, it will execute in all run cycle modes (which, to be precise, are declared as part of a set of "common" modes). This means that the timer works not only in NSDefaultRunLoopMode, but also in NSEventTrackingRunLoopMode (when the user touches the screen).
So, after initializing the timer, add it to NSRunLoopCommonModes:
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
joern source share