iOS中的CADisplayLink定时器
说到定时器,在iOS中最常用的为NSTimer类,其实CADisplayLink类在某些场景下使用,要比NSTimer类更加适合。首先CADisplayLink也是一种定时器,并且其和屏幕的刷新率始终保持一致(很多时候会使用CADisplayLink来检测屏幕的帧率)。由于CADisplayLink的这种特性,使用它来实现流畅的动画效果非常合适。
CADisplayLink类非常简单,解析如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
+ (CADisplayLink *)displayLinkWithTarget:(id)target selector:(SEL)sel;
- (void)addToRunLoop:(NSRunLoop *)runloop forMode:(NSRunLoopMode)mode;
- (void)removeFromRunLoop:(NSRunLoop *)runloop forMode:(NSRunLoopMode)mode;
- (void)invalidate;
@property(readonly, nonatomic) CFTimeInterval timestamp;
@property(readonly, nonatomic) CFTimeInterval duration;
@property(readonly, nonatomic) CFTimeInterval targetTimestamp;
@property(getter=isPaused, nonatomic) BOOL paused;
@property(nonatomic) NSInteger preferredFramesPerSecond CA_AVAILABLE_IOS_STARTING(10.0, 10.0, 3.0);
@property(nonatomic) NSInteger frameInterval CA_AVAILABLE_BUT_DEPRECATED_IOS (3.1, 10.0, 9.0, 10.0, 2.0, 3.0, "use preferredFramesPerSecond");
|
我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=29qwh7m53g4kc