1.创建
NSTimer *_timer;
2.使用
_timer = [NSTimer scheduledTimerWithTimeInterval:0.5f target:self selector:@selector(nextTime) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
3.开启与关闭
-(void)nextTime
{
//关闭定时器
[_timer setFireDate:[NSDate distantFuture]];
//开启定时器
//[_timer setFireDate:[NSDate distantPast]];
}
4.注销
-(void)dealloc
{
//释放定时器
[_timer invalidate];
_timer = nil;
}