运行循环
来源:互联网 发布:医疗大数据公司排名 编辑:程序博客网 时间:2024/04/30 10:55
运行循环 - 负责所有事情的监听
模式决定了事件的级别
1.重要概念
1. 保证应用程序不退出
2. 监听所有的事件
3.如果没有事件发生,运行循环会进入休眠状态,等到事件发生后 重新启动
4.子线程的运行循环默认是不启动的
5.主线程的运行循环默认是开启的
NSDefaultRunLoopMode 时钟网络...
NSRunLoopCommonModes:用户交互,响应级别高,一旦触发时间和网络都会暂停
self.timer= [NSTimertimerWithTimeInterval:1.0target:selfselector:@selector(updateTimer)userInfo:nilrepeats:YES];
// 表示发生用户交互的时候,时钟仍然会触发!
// 表示发生用户交互的时候,时钟仍然会触发!
[[NSRunLoopcurrentRunLoop] addTimer:self.timerforMode:NSRunLoopCommonModes];
//调度时钟,默认将时钟以 NSDefaultRunLoopMode 模式添加到运行循环
// self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES];
如果触发方法非常耗时,使用NSRunLoopCommoModes 会造成卡顿
dispatch_async(dispatch_get_global_queue(0,0), ^{
// 在子线程开启时钟!由于子线程的运行循环没有启动,所以没法监听时钟事件
self.timer= [NSTimertimerWithTimeInterval:1.0target:selfselector:@selector(updateTimer)userInfo:nilrepeats:YES];
// 表示发生用户交互的时候,时钟仍然会触发!
[[NSRunLoopcurrentRunLoop]addTimer:self.timerforMode:NSDefaultRunLoopMode];
// 开启运行循环 - 启动运行循环 - 这句代码就是一个死循环!
// 如果不停止运行循环,不会执行后续的任何代码
// 一旦停止了运行循环,后续代码能够执行,执行完毕后,线程被自动销毁!
CFRunLoopRun();
NSLog(@"come here");
});
}
0 0
- 运行循环
- 91- 运行循环:RunLoop
- NSRunLoop(运行循环)
- 186,NSRunLoop运行循环
- iOS 运行循环简介
- RunLoop运行循环
- iOS开发-运行循环
- 多线程:模拟循环运行
- NSTimer 运行循环
- 运行循环-RunLoop
- 运行循环(Run Loops)
- Runloop运行循环的作用
- 【读书笔记】iOS网络-运行循环
- 运行循环RunLoop原理剖析
- iOS 【Mutithreading-NSRunLoop 运行循环】
- 事件流(循环过程)运行流程
- 事件流(循环过程)运行流程
- 如何提升JavaScript循环的运行速度
- FindBugs插件的安装与使用
- SDWebImage 第三方框架
- 安卓学习知识点总结一
- 源码解析Volley框架
- LeetCode OJ ——Find Minimum in Rotated Sorted Array
- 运行循环
- [leetcode]Remove Element
- js 字符串转日期
- C语言学习web服务器小实例
- 排序算法的时间复杂度
- ubuntu14.04系统nodejs express开发教程第二篇:添加controllers && services
- iOS 开发、测试、生产证书的创建
- iOS 9 Storyboard 教程(二上)
- oracle函数大全