nstimer注意事项

Posted 柳仙慧子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nstimer注意事项相关的知识,希望对你有一定的参考价值。

当nstimer在主线程创建时,当滑动时,系统为了更好的处理UI事件,会暂停timer,解决办法就是改变timer的mode,不使用缺省的NSDefaultRunLoopMode,而是改用NSRunLoopCommonModes

NSTimer *timer = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(timer:) userInfo:nil repeats:YES];

[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

以上是关于nstimer注意事项的主要内容,如果未能解决你的问题,请参考以下文章