0
点赞
收藏
分享

微信扫一扫

延迟操作



1. GCD 延迟5秒在主线程执行

(延迟5秒执行block里面的代码)

// 创建线程 time(第一个参数: 从现在开始, 第二个参数延迟的时间)
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)5.0 * NSEC_PER_SEC);
dispatch_after(time, dispatch_get_main_queue(), ^{

self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(nextPicture) userInfo:nil repeats:YES];
[self.timer fire];
});

2. 主线程延迟执行 5s

[NSThread sleepForTimeInterval:5];




3. self.tom这个对象 延迟self.tom.animationDuration 后 执行 setAnimationImages:这个方法

[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration] 



举报

相关推荐

0 条评论