-(IBAction)btnClick{ [self starTimer];//开始计时 //[self stopTimer]; } -(NSTimer*)timer{ if (!_timer) { _timer =[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(beginChange) userInfo:nil repeats:YES]; } return _timer; } //暂停定时器(只是暂停,并没有销毁timer) -(void)pauseTimer{ [self.timer setFireDate:[NSDate distantFuture]]; } //继续计时 -(void)continueTimer{ [self.timer setFireDate:[NSDate distantPast]]; } //开始计时 -(void)startimer{ [self.timer fire]; } //暂停并销毁 -(void)stopTimer{ [self.timer invalidate]; self.timer = nil; } //开启定时器 -(void)starTimer{ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(timerStar) object:nil]; [self performSelector:@selector(timerStar) withObject:nil afterDelay:1]; }