【发布时间】:2017-10-21 13:42:20
【问题描述】:
我有 NSTimer 和 Action。但我想在第一次 5 秒后调用 Action,第二次在 4 秒后调用 ...。
_timepast = 6;
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(handleDelay) userInfo:nil repeats:YES];
-(void)handleDelay
{
_timepast = _timepast - 1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_timepast * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self handleTimer];
});
}
【问题讨论】:
-
所以这意味着你想要倒计时,对吧?
-
@HardikShah 是的,没错。
标签: ios objective-c nstimer