CADisplayLink的简单使用
生活随笔
收集整理的這篇文章主要介紹了
CADisplayLink的简单使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
CADisplayLink類似NSTimer是一個定時器,只不過是一秒會調用60次指定的方法
使用方法:
#import "ViewController.h"@interface ViewController ()@property (nonatomic, strong) CADisplayLink *displayLink; @property (nonatomic, assign) int count;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 創建CADisplayLinkself.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkEvent)];[self performSelector:@selector(eventOne) withObject:nil afterDelay:1];// 一秒后銷毀[self performSelector:@selector(eventTwo) withObject:nil afterDelay:2]; }- (void)eventTwo {[self.displayLink invalidate]; }- (void)eventOne {// 添加到循環圈(開始執行) [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; }- (void)displayLinkEvent {self.count++;NSLog(@"%i",self.count); }@end?其中,displayLinkEvent方法在一秒內被調用了60次。
轉載于:https://www.cnblogs.com/Rinpe/p/5158693.html
總結
以上是生活随笔為你收集整理的CADisplayLink的简单使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SMACH专题(一)----安装与初探
- 下一篇: (王道408考研操作系统)第二章进程管理