计算当前CADisplayLink时间

_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayAction:)];
    [_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
-(void)displayAction:(id)sender
{
    if (_lastTime == 0) {
        _lastTime = _displayLink.timestamp;
        return;
    }

    _count++;
    NSTimeInterval delta = _displayLink.timestamp - _lastTime;
    if (delta < 1) return;
    _lastTime = _displayLink.timestamp;
    float fps = _count / delta;
    _count = 0;

    NSString *text = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%d FPS", (int)round(fps)]];

    _numLabel.text = text;
}

你可能感兴趣的:(计算当前CADisplayLink时间)