·您现在的位置: 江北区云翼计算机软件开发服务部 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> 关于OC中的几种代码延迟执行方式

关于OC中的几种代码延迟执行方式

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23
第一种: [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];//不阻塞线程