美文网首页
CADisplayLink 定时器

CADisplayLink 定时器

作者: seventhboy | 来源:发表于2018-10-10 15:33 被阅读25次

    -(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;
    }
    }

    相关文章

      网友评论

          本文标题:CADisplayLink 定时器

          本文链接:https://www.haomeiwen.com/subject/hanpaftx.html