zoukankan      html  css  js  c++  java
  • iOS 几种定时器

        //第一种 每一秒执行一次(重复性)
        double delayInSeconds = 1.0;
        timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
        dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC, 0.0);
        dispatch_source_set_event_handler(timer, ^{
            NSLog(@"timer date 1== %@",[NSDate date]);
        });
        dispatch_resume(timer);
        
        //第二种 二秒后执行 (一次性)
        double delayInSeconds = 2.0;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            NSLog(@"timer date 2== %@",[NSDate date]);
        });
        
        //第三种 每一秒执行一次 (重复性)
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(testTimer) userInfo:nil repeats:YES];

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    2016.10.09
    Httpie 进行web请求模拟
    Python-集合
    python-字典
    MySQL权限系统
    MySQL8.0安装以及介绍(二进制)
    数据库对象中英文介绍
    Python-字符串
    GIT安装部署
    Cobbler安装部署
  • 原文地址:https://www.cnblogs.com/zsw-1993/p/4879499.html
Copyright © 2011-2022 走看看