CADisplayLink定时器的使用

//初始化使用定时器
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(test)];
//设置时间间隔(CADisplayLink 默认每秒运行60次)该属性设置伟60代码1s
link.frameInterval = 60.0;
[link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
//定时器暂停
ink.paused = YES;
//定时器继续
link.paused = NO;
//定时器销毁
[link invalidate];

NSTimer使用

NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(方法名) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop mainRunLoop];
[runLoop addTimer:timer forMode:NSRunLoopCommonModes];

你可能感兴趣的:(CADisplayLink定时器的使用)