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;

    }

     
  • 相关阅读:
    css word-wrap与word-break区别
    input输入框光标位置问题
    正则表达式(二)- 位置匹配攻略
    正则表达式(一)- 字符匹配攻略
    mac电脑重启nginx报错nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx.pid"
    指定js文件不使用 eslint 语法检查
    管理github/gitlab生成多个ssh key
    前端切图两种方法整理
    梳理:移动端Viewport的知识
    切图 — Photoshop(转载)
  • 原文地址:https://www.cnblogs.com/lijianyi/p/4278455.html
Copyright © 2011-2022 走看看