#import "ViewController.h"
@interface ViewController ()
{
CADisplayLink *displayLink;
NSInteger time;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateDisplay:)];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];//添加到循环并启动
displayLink.frameInterval = 60;//设置帧率为每秒一次(默认为每秒60次)
//控制计时器暂停与恢复的属性。设置为YES的时候会暂停事件的触发
displayLink.paused = YES;
time = 60;//设置时间
}
//刷新时调用
- (void)updateDisplay:(CADisplayLink *)cadisplaylink{
time -= 1;
if (time == 0) {
[displayLink invalidate];
}
NSLog(@"time:%ld", (long)time);
}