使用NSTimer来实现
主要使用的是NSTimer的scheduledTimerWithTimeInterval方法来每1秒执行一次timeFireMethod函数,timeFireMethod进行倒计时的一些操作,完成时把timer给invalidate掉就ok了,代码如下:
secondsCountDown = 60;//60秒倒计时
countDownTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
-(void)timeFireMethod{
secondsCountDown--;
if(secondsCountDown==0){
[countDownTimer invalidate];
}
}