CADisplayLink 的基本使用方法

标签: 

转载

分类: [iPhone开发]
[转载]CADisplayLink <wbr>的基本使用方法  [转载]CADisplayLink <wbr>的基本使用方法

自從 iOS SDK 3.1 起就增加了 CADisplayLink Class,這個 Class 的功能類似於 Timer。由於能支援每秒高達 60 fps 的畫面同步功能,所以更適合用在製作遊戲動畫上面,相較之下 Timer 較常使用在背景處理層面,其基本使用方式如下。(View-based Template)

第一步要先引入 CADisplayLink 的標頭檔,才能真正使用它。

1#import <QuartzCore/CADisplayLink.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
//自行定義的函式,用來設定使用CADisplayLink的相關參數
-(void)initializeTimer {
 
    //theTimer是CADisplayLink型態的指標,用來存放當前的設定狀態
    theTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(countTotalFrames)];
 
    //CADisplayLink內定值就是每秒60張(參數=1),參數=2就是每秒30張,以此類推
    double fps = 60 / theTimer.frameInterval;
    fpsLabel.text = [NSString stringWithFormat:@"%0.1f" , fps];
 
    //設定執行狀態並啟動theTimer
    [theTimer addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}

转载于:https://www.cnblogs.com/monnRedShine/archive/2013/06/13/3134093.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值