iOS中的两个定时器:
@property(nonatomic,strong)NSTimer* timer;
1.1手动加入消息循环
// 开启定时器
-(void)startTimer{
self.timer=[NSTimer timerWithTimeInterval:3 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
// 移除定时器
- (void)stopTimer
{
[self.timer invalidate];
self.timer = nil;
}
——————————————————————————————————————————————————————————————————————————————————
1.2 自动加入消息循环
// 开启定时器
-(void)startTimer
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];
}
// 移除定时器
- (void)stopTimer
{
[self.timer invalidate];
self.timer = nil;
}
2.
@property(nonatomic,strong)CADisplayLink* link;
//开启定时器
-(void)startTimer
{
self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateLrc)];
[self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
//移除定时器
- (void)stopTimer
{
[self.link invalidate];
self.link = nil;
}