NSTimer是iOS系統(tǒng)中常用的定時器,一般用來實現(xiàn)從現(xiàn)在起到未來的末裔時刻要執(zhí)行或者循環(huán)執(zhí)行某一個方法
用法一:用一個按鈕來控制定時器的開始和停止
- (IBAction)startOrStopAction:(id)sender {
if([self.timer isValid]) { //判斷當(dāng)前定時器的狀態(tài)
[self.timer invalidate];
}else{
//配置定時器
self.timer= [NSTimer scheduledTimerWithTimeInterval:0.2 target: self selector:@selector(timerAction:) userInfo: nil repeats: YES];
? }
}