定时器里面有个runoop mode,一般定时器是运行在defaultmode上。但是如果滑动了这个页面,主线程runloop会转到UITrackingRunLoopMode中,这时候就不能处理定时器了,造成定时器失效,原因就是runroop mode选错了,解决办法有2个
一个是更改mode为NSRunLoopCommonModes(无论runloop运行在哪个mode,都能运行),
还有种办法是切换到主线程来更新UI界面的刷新
[NSThread detachNewThreadSelector:@selector(bannerStart) toTarget:self withObject:nil];
- (void)bannerStart{
_shufflingFigureTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(shufflingFigureTimerAction:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_shufflingFigureTimer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
}
网友评论