第一种:
[UIView animateWithDuration:3 delay:3 options:1 animations:^{
        self.btn.transform = CGAffineTransformMakeTranslation(300, 400);
    } completion:^(BOOL finished) {
        NSLog(@"view animation结束");
    }];//不会阻塞线程,animations  block中的代码对于是支持animation的代码,才会有延时效果,
         对于不支持animation的代码 则 不会有延时效果
 
第二种:
[NSThread sleepForTimeInterval:3];//阻塞线程,浪费性能 ,一般不推荐用
 
第三种:最常用
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
       
    });//定制了延时执行的任务,不会阻塞线程,效率较高(推荐使用)
  
第四种:
[self performSelector:@selector(test) withObject:nil afterDelay:3];//不阻塞线程
 

相关文章:

  • 2021-09-30
  • 2021-09-26
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-03-26
相关资源
相似解决方案