如何在 mainRunloop 中使用 CADisplaylink 循环调用我更改视图位置以显示动画的方法
how to use CADisplaylink in mainRunloop to cycle call a method in which I changed a view's position to show a animation
我想在我的视图中显示动画。所以我使用 CADisplaylink
作为计时器,这样它会在一秒钟内调用更新方法 60 次 ( 60FPS).
但是当同一个超级视图中的表视图重新加载时,CADisplaylink
每秒只调用 40-50 次(40-50FPS)。
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
self.displayLink.paused = YES;
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
我该如何解决?
来自 CADisplayLink class 参考:
The target can read the display link’s timestamp property to retrieve
the time that the previous frame was displayed. For example, an
application that displays movies might use the timestamp to calculate
which video frame will be displayed next. An application that performs
its own animations might use the timestamp to determine where and how
displayed objects appear in the upcoming frame. The duration property
provides the amount of time between frames. You can use this value in
your application to calculate the frame rate of the display, the
approximate time that the next frame will be displayed, and to adjust
the drawing behavior so that the next frame is prepared in time to be
displayed.
意思是帧速率由系统决定,您的动画应该以此为基础。无法设置帧速率,而是由多种因素共同决定(例如,处理器密集型活跃活动的活跃程度、UI 的图形密集程度等)。
我想在我的视图中显示动画。所以我使用 CADisplaylink
作为计时器,这样它会在一秒钟内调用更新方法 60 次 ( 60FPS).
但是当同一个超级视图中的表视图重新加载时,CADisplaylink
每秒只调用 40-50 次(40-50FPS)。
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
self.displayLink.paused = YES;
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
我该如何解决?
来自 CADisplayLink class 参考:
The target can read the display link’s timestamp property to retrieve the time that the previous frame was displayed. For example, an application that displays movies might use the timestamp to calculate which video frame will be displayed next. An application that performs its own animations might use the timestamp to determine where and how displayed objects appear in the upcoming frame. The duration property provides the amount of time between frames. You can use this value in your application to calculate the frame rate of the display, the approximate time that the next frame will be displayed, and to adjust the drawing behavior so that the next frame is prepared in time to be displayed.
意思是帧速率由系统决定,您的动画应该以此为基础。无法设置帧速率,而是由多种因素共同决定(例如,处理器密集型活跃活动的活跃程度、UI 的图形密集程度等)。