• 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];
    }
  • 相关阅读:
    HDU2201
    HDU2202 凸包
    HDU 4353 几何
    POJ2031 prim
    HDU1392 凸包
    HDU1689 BFS+最小奇数环
    设计模式 [转]
    Mining Massive Data Sets PPT
    C++编程命名规范 [转]
    static_cast与dynamic_cast转换 [转]
  • 原文地址:https://www.cnblogs.com/monnRedShine/p/3134093.html
Copyright © 2020-2023  润新知