核心就是在控制器中创建计时器,然后在模型中倒计时时间
//计时器
- (void)setUpTimer {
self.timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerEvent) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)timerEvent {
for (CZHCountDownModel *timeModel in self.timeArrays) {
if (timeModel.startTime - timeModel.currentTime <= 0) {
continue;
}
[timeModel countDown];
[[NSNotificationCenter defaultCenter] postNotificationName:CZHUpdateTimeNotification object:nil];
}
}

公司的项目,求支持,如果发现什么问题,可以留言反应,感激不尽
本文介绍了一种在iOS应用中实现倒计时功能的方法。通过在控制器中创建并启动计时器,定时更新模型中的倒计时状态,并利用NSNotification通知机制同步视图更新。
2万+

被折叠的 条评论
为什么被折叠?



