Apple开发_定时器

1、几种定时介绍

2、定时任务

  • 1)performSelector

// 1.5 秒后自动调用 self 的 hideHUD 方法
[self performSelector:@selector(hideHUD) withObject:nil afterDelay:1.5];

// 取消延时调用
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(hideHUD) object:nil];

- (void)hideHUD {

}
  • 2)GCD

// GCD定时器:1.5 秒后自动执行 block 里面的代码
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

    self.hud.alpha = 0.0;
});
  • 3)NSTimer

// 1.5 秒后自动调用 self 的 hideHUD 方法
[NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(hideHUD) userInfo:nil repeats:NO];
posted @ 2019-02-17 22:24  CH520  阅读(274)  评论(0编辑  收藏  举报