-(void)startTimer {
[self invalidateTimer];
self.displayTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(captureView:)];
if (@available(iOS 10.0, *)) {
self.displayTimer.preferredFramesPerSecond = desiredFrameRate;
} else {
self.displayTimer.frameInterval = displayLinkFrameRate / desiredFrameRate;
}
[self.displayTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
self.displayTimer.paused = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground;
}
-(void)invalidateTimer{
if(self.displayTimer){
[self.displayTimer invalidate];
self.displayTimer = nil;
}
}
网友评论