延迟操作
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]
(延迟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]
相关文章推荐
- Struts的一些总结
- 在Linux运行期间升级Linux系统(Uboot+kernel+Rootfs)
- 工作杂谈
- HTML
- 【转】Java 集合系列目录(Category)
- 寻找最小k个数或者寻找第K大的数字
- Android发送邮件
- 瞎搞
- Apache之——配置虚拟目录(监听多个端口)
- 软工视频总结(1)-----前五讲回顾
- eMMC分区详解
- 【详解】嵌入式开发中固件的烧录方式
- JavaScript我学之八善变的this---函数执行上下文
- 文化:要么牛逼,要么滚蛋(美团)
- uva 1438 - Asteroids(几何重心+凸包)
- DISTINCT选取多个字段,只DISTINCT一个字段的解决办法
- 2.1.2、构建一个基础镜像
- Android获取当前电量信息(BroadcastReceiver的使用)
- tomcat日志缓存问题
- 从短信的处理看属性分类的应用