首页 > 学院 > 开发设计 > 正文

CADisplayLink

2019-11-08 00:09:05
字体:
来源:转载
供稿:网友
- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.//    _scrollView = [UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self., <#CGFloat height#>)    self.view.backgroundColor = [UIColor whiteColor];    self.edgesForExtendedLayout = UIRectEdgeNone;    self.view.height -= 64;            _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 200) style:UITableViewStylePlain];    _tableView.delegate = self;    _tableView.dataSource = self;    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];        [self.view addSubview:_tableView];        _label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 200, 90)];    _label2 = [[UILabel alloc] initWithFrame:CGRectMake(100, 350, 200, 90)];        [self.view addSubview:_label];    [self.view addSubview:_label2];        _link = [CADisplayLink  displayLinkWithTarget:self selector:@selector(update)];    [_link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];}- (void)update {    static int i = 0;    _label.text = [NSString stringWithFormat:@"i:%d", ++i];    _label2.text = [NSString stringWithFormat:@"fps:%ld", 60/_link.frameInterval];}

Link的启动方法就是addToRunloop。

label2可以显示fps值,非常好用!

如果用 NSDefaultRunLoopMode 那么tableView滚动时,label就不变了,i值不变了!所以最好改成commonMode!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表