zoukankan      html  css  js  c++  java
  • iOS 时钟动画

       在iOS开发中,定时器NSTimer并不能够准确的出发,通常使用NSTimer只能控制不需要精确处理的操作,而CADisplayLink就是在每次屏幕刷新时,通知系统。CADisplayLink最大的好处就是可以精准的在每次屏幕刷新时,设置屏幕的重绘!

      示例代码:

      

     1 #import "WKViewController.h"
     2 
     3 @interface WKViewController ()
     4 
     5 @end
     6 /**
     7  
     8  */
     9 @implementation WKViewController
    10 {
    11     CADisplayLink *_timer;
    12 }
    13 
    14 - (void)viewDidLoad
    15 {
    16     [super viewDidLoad];
    17     
    18     _timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(snow)];
    19     // 将时钟添加到主运行循环,才能够在每次屏幕刷新时工作
    20    //每秒60次
    21     [_timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
    22 }
    23 
    24 
    25 - (void)snow
    26 {
    27     //用于控制多少时间操作一次
    28     static long counter = 0;
    29     
    30     counter++;
    31     
    32     if (counter % (15) == 0) {
    33           //do something
    34     }
    35    
    36 }
    37 
    38 
    39 @end
  • 相关阅读:
    Mysql日志管理
    Mysql 安全和DCL语句
    Mysql DDL语句之视图
    Mysql增删改查(DML、DQL)
    Mysql操作之部分DDL语句
    如何做事情
    temp
    asp.net入门
    希望尽快回忆起来
    需求?
  • 原文地址:https://www.cnblogs.com/pretty-guy/p/4067495.html
Copyright © 2011-2022 走看看