static int count = 0;
NSTimer *timer = [NSTimer timerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
NSLog(@"%d",++count);
}];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
由于NSTimer运行模式在runloop循环中属于kCFRunLoopDefaultMode模式,
而scrollview在滚动中在runloop循环中属于UITrackingRunLoopMode模式。
故如果要解决这个问题,可以把timer加入到NSRunLoopCommonModes这个模式中,此模式不是一个真实存在的模式,二是一个标记。
runloop与timer的关系:
runloop包含modes,modes里面含有timer,而timer可以唤醒runloop。