zoukankan      html  css  js  c++  java
  • iOS中的定时器

    iOS中的两个定时器:

    1.NSTimer  ------>简单使用,时间多于1秒使用
    2.CADisplayLink  ------>简单使用,时间小于一秒使用,每秒调用60次
     

    @property(nonatomic,strong)NSTimer* timer;

    1.1手动加入消息循环

    // 开启定时器

    -(void)startTimer{

        self.timer=[NSTimer timerWithTimeInterval:3 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];

        

        [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];

        

    }

    // 移除定时器

    - (void)stopTimer

    {

        [self.timer invalidate];

        self.timer = nil;

    }

    ——————————————————————————————————————————————————————————————————————————————————

    1.2 自动加入消息循环

    // 开启定时器

    -(void)startTimer

    {

             self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];

       

    }

     // 移除定时器

    - (void)stopTimer

    {

        [self.timer invalidate];

         self.timer = nil;

    }

    ——————————————————————————————————————————————————————————————————————————————————

    2.

    @property(nonatomic,strong)CADisplayLink* link;

     //开启定时器

    -(void)startTimer

    {

           self.link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateLrc)];

        [self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];

    }

    //移除定时器

    - (void)stopTimer

    {

        [self.link  invalidate];

        self.link  = nil;

    }

     
  • 相关阅读:
    Dynamics CRM The difference between UserId and InitiatingUserId in Plugin
    Dynamics CRM2013 6.1.1.1143版本插件注册器的一个bug
    Dynamics CRM2013 从subgrid中打开快速创建窗体创建数据
    求逆元 HDU1576
    多个数的最小公倍数 HDU1019
    快速幂 HDU3003
    扩展欧几里德算法求逆元1
    筛法求素数 函数模板
    矩阵模板
    快速幂取模函数 递归模板
  • 原文地址:https://www.cnblogs.com/lijianyi/p/4278455.html
Copyright © 2011-2022 走看看