最近公司项目很多地方都用了定时器,自己简单封装了个gcdtimer的工具类。 很多人应该都知道NSTimer开启定时器在某些开发情景下会由于NSRunloop的原因造成延时,当然项目要求不高可以直接用NSTimer,如果对定时器要求高可以下载这个封装的gcdtimer工具去做。废话不多说、直接上代码、大家多多指教。
开启定时器:
__weak typeof(self) weakSelf = self;
[[LHY_GCDTimer shareInstance] scheduledDispacthTimerWithName:@"timerone" timerInterval:1.0 queue:nil repeats:YES action:^{
[weakSelf test];
}];
取消定时器:
[[LHY_GCDTimer shareInstance] cancelGcdTimerWithName:@"timerone"];