iOS开发笔记>> 以 schedcledTimerWithTimerInterval…的方式触发的 timer,在滑动页面上的列表时,timer 会暂停回调,为什么?如何解决?
来源:互联网 发布:淘宝发帖怎么删除 编辑:程序博客网 时间:2024/06/11 21:40
遇到的问题:
timer 本身不能自动循环的做一些事, 必须把它加入到消息循环后才能处理一些事情, 而用 scheduleTimerWithTimeInterval 的方式创建的 timer 做了两件事情:
1. 创建了 NSTimer 对象
2. 把这个 timer 加入到当前 RunLoop 的 NSDefaultRunLoopMode 中
因为线程一般情况下就是 NSDefaultRunLoopMode 模式, 而刚用 scheduleTimerWithTimeInterval 方式创建的 timer 也是加入到 NSDefaultRunLoopMode 中的, 因此子啊平时情况下, NSTimer 都能正常工作, 但当你在界面上进行滑动时, 当前的 RunLoop 会立即进入 UITrachingRunLoopMode 模式, 此时与 timer 所加入的模式并不是同一种, 因此 timer 就会暂时停止回调, 直到停止滑动, 从 UITrachingRunLoopMode 转回 NSDefaultRunLoopMode 时才能继续正常工作.
解决办法:
用 scheduleTimerWithTimeInterval 的方式创建完 timer 对象后, 立即获取当前线程的 RunLoop, 然后添加 timer 到 NSRunLoopCommomModes 中, 因为 NSRunLoopCommomModes 模式代表把 timer 加入到所具有"Common"属性标记的模式中. 而 NSDefaultRunLoopMode 和 UITrachingRunLoopMode 这两种模式都具有"Common"属性标记.
- iOS开发笔记>> 以 schedcledTimerWithTimerInterval…的方式触发的 timer,在滑动页面上的列表时,timer 会暂停回调,为什么?如何解决?
- 调用+scheduledTimerWithTimeInterval...的方式触发的timer,在滑动页面上的列表时,timer会暂停回调,为什么?如何解决?
- 以+scheduledTimerWithTimeInterval... 的方式触发的 timer,在滑动页面上的列表时, timer 会暂定回调,为什么?如何解决?
- 用ssk皮肤后timer不触发问题的解决
- 解决IOS滑动触发Body的滑动
- android Timer/TimerTask的暂停和开始
- 用在计时器上的“神器”------Timer
- C#中Timer的触发问题
- 在C#的ajax中的timer触发函数中怎样调用页面元素和引用JS脚本函数?
- Timer 的Timer schedule()方法
- timer的一个使用方法,解决timer无效的问题
- runLoop 添加timer的正确方式 (ios oc)
- jbpm3的timer开发问题
- Android使用Timer会不准的问题
- 解决页面使用overflow: scroll在iOS上滑动卡顿的问题
- 如何操作客户端上的 AJAX Timer 控件?
- 如何手工创建Timer控件,并且在Timer控件的事件中控制窗体控件
- java Timer为什么是线程安全的
- 暑假集训 8.11 树结构练习——排序二叉树的中序遍历 sdutoj2128
- 视频直播本地测试服务器搭建
- 拆解Clucene系列(3)——Clucene的代码组织结构
- maven使用
- Volley
- iOS开发笔记>> 以 schedcledTimerWithTimerInterval…的方式触发的 timer,在滑动页面上的列表时,timer 会暂停回调,为什么?如何解决?
- android自定义Dialog
- yii2 mail config
- jquery中$.ajax()方法详解
- jQuery 图表插件 jqChart 使用绘制雷达图
- HDU 1272 并查集 图和并查集的结合
- SFTP资源文件下载
- Java/Android
- 前端,HTML,JS