Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

30. 以+ scheduledTimerWithTimeInterval...的方式触发的timer,在滑动页面上的列表时,timer会暂定回调,为什么?如何解决? #107

Open
CodingPub opened this issue Sep 5, 2018 · 0 comments

Comments

@CodingPub
Copy link
Contributor

最终答案中只需要

//创建 Timer,然后添加到 NSRunLoopCommonModes
NSTimer *timer = [NSTimer timerWithTimeInterval:1.0
     target:self
     selector:@selector(timerTick:)
     userInfo:nil
     repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

就能解决 Timer 计时会被 scrollView 的滑动影响。

增加下面的代码会导致无滑动事件时,计时器回调两次,因为 NSRunLoopCommonModes 包括了 UITrackingRunLoopMode 和 NSDefaultRunLoopMode

//将timer添加到NSDefaultRunLoopMode中
[NSTimer scheduledTimerWithTimeInterval:1.0
     target:self
     selector:@selector(timerTick:)
     userInfo:nil
     repeats:YES];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant