CADisplayLink最主要的特征是能提供一个周期性的调用我们赋给它的selector的机制,从这点上看它很像定时器NSTimer。
- (void)startTimerWithRepeatSeconds:(NSInteger)seconds{
[_countdownTimerinvalidate];
_countdownTimer =nil;
if (_timer ==nil) {
_timer = [CADisplayLinkdisplayLinkWithTarget:selfselector:@selector(queryWashStatus)];
[_timeraddToRunLoop:[NSRunLoopmainRunLoop] forMode:NSDefaultRunLoopMode];
// _timer = [NSTimer scheduledTimerWithTimeInterval:seconds target:self selector:@selector(queryWashStatus) userInfo:nil repeats:true];
}
//32秒间隔
_timer.frameInterval =seconds*60;//link必须乘60才能一帧一次
//iOS设备的屏幕刷新频率(FPS)是60Hz,因此CADisplayLink的selector 默认调用周期是每秒60次,这个周期可以通过frameInterval属性设置, CADisplayLink的selector每秒调用次数=60/ frameInterval。
}