timer-線程問題
問題原因:
一般定時器timer都會被以默認(rèn)模式default添加到主線程的runloop中,當(dāng)滑動界面時,runloop接到信息處理事件,就會改變timer的運(yùn)行模式到tracing,從而停止運(yùn)行timer。
解決方法:
1、改變timer添加到runloop中的模式:
[[NSRunLoop currentRunLoop] addTimer:_shufflingFigureTimer forMode:NSRunLoopCommonModes];
2、把timer添加到支線程
[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];
}