您的位置:首页 > 其它

延迟操作

2015-08-31 23:03 344 查看
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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: