您的位置:首页 > 其它

定时器 NSTimer 开始、暂停、继续、停止

2016-03-04 00:00 447 查看
定时器 NSTimer

开始

if (_timer==nil) {
_timer = [NSTimer  scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(startFly) userInfo:nil repeats:YES];
}

暂停

if (_timer!=nil) {
//定时器暂
[_timer setFireDate:[NSDate distantFuture]]
}

继续

if(_timer){
//定时器继续
[_timer  setFireDate:[NSDate distantPast]];
}

停止

//停止定时器,销毁定时器
if (_timer) {
[_timer invalidate];
_timer = nil;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: