四个简单易用的demo,关于iOS定时器和延时的,非常好用。
2024-08-29 19:38:41
1,延时执行(不可重复)
效果我直接截取控制台的日志了,就不做UI了。
2,用NSTimer执行定时和延时(可重复)
[objc] view plain copy /**
** timer 可重复
**/
- (void)timerMethodB
{
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f //间隔时间
target:self
selector:@selector(methodBEvnet)
userInfo:nil
repeats:YES];
} - (void)methodBEvnet
{
count++;
NSLog(@"-- Method_B count: %d", count); if (count >= ) {
[_timer invalidate]; //重复5次,timer停止
NSLog(@"-- end");
}
}
3,用dispatch_source_set_timer执行定时(可重复)
4,用dispatch_after执行延时(不可重复)
文章最后奉上demo
http://download.csdn.net/detail/xiongbaoxr/9417374
最新文章
- 导入 cocoapods引入的第三方库头文件,提示找不到
- vs2010中的MSBuild输出warning MSB8012问题
- iOS开发-图片高斯模糊效果
- Stationary point
- ext 3.2 tree 在IE10中点击事件失效的bug
- Macbook之设置Finder显示文件完整路径
- [读书笔记]了不起的node.js+实践(一)
- onbeforeunload、beforeunload
- 金蝶K3无法创建数据库,请查看该文件夹的错误的解决方法。
- unity 退到桌面的 OnApplicationPause
- UVA 10759 Dice Throwing
- Leetcode题解(十一)
- Angular之ngRoute与uiRoute
- 记录Linux CentOS 7系统完整部署Docker容器环境教程
- java课程之团队开发冲刺1.1
- MySql cmd下的学习笔记 —— 有关修饰器的知识(trigger)
- XE5开发Android程序调用电话相关功能(短信息和电话)
- CGLib缺少jar出现 java.lang.ClassNotFoundException: org.objectweb.asm.Type
- Spring-IOC bean 创建过程中的 ObjectFactory
- P1414 又是毕业季II