NSTimer

  NSTimer *timer = [NSTimer timerWithTimeInterval:1 repeats:YES block:^(NSTimer * _Nonnull timer) {
        
    }];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    [[NSRunLoop currentRunLoop] run];

timer加入runloop,自动进入倒计时.
[timer setFireDate:[NSDate distantFuture]]; //倒计时暂停
[timer setFireDate:[NSDate distantPast]]; //继续倒计时

[timer invalidate];//倒计时永久停止,但不会释放内存为空.

你可能感兴趣的:(NSTimer)