美文网首页
RunLoop与NSTimer

RunLoop与NSTimer

作者: bugLife丶 | 来源:发表于2019-07-25 15:42 被阅读0次

一个比较常见的问题:滑动tableView时,定时器还会生效吗? 默认情况下RunLoop运行在kCFRunLoopDefaultMode下,而当滑动tableView时,RunLoop切换到UITrackingRunLoopMode,而Timer是在kCFRunLoopDefaultMode下的,就无法接受处理Timer的事件。 怎么去解决这个问题呢?把Timer添加到UITrackingRunLoopMode上并不能解决问题,因为这样在默认情况下就无法接受定时器事件了。 所以我们需要把Timer同时添加到UITrackingRunLoopMode和kCFRunLoopDefaultMode上。 那么如何把timer同时添加到多个mode上呢?就要用到NSRunLoopCommonModes了

[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

Timer就被添加到多个mode上,这样即使RunLoop由kCFRunLoopDefaultMode切换到UITrackingRunLoopMode下,也不会影响接收Timer事件

相关文章

  • iOS面试之RunLoop模块

    RunLoop RunLoop内容如下 概念 数据结构 事件循环 RunLoop与NSTimer RunLoop与...

  • OC--RunLoop应用例子

    知识点:1、RunLoop的基础知识2、RunLoop 与 NSTimer3、RunLoop 与 Perform ...

  • NSTimer的循环引用

    NSTimer基本使用 NSTimer与RunLoop NSTimer 循环引用的问题 如何在子线程使用NSTim...

  • iOS开发 之 不要告诉我你会用NSTimer!

    目录 引言 创建NSTimer 销毁NSTimer NSTimer与runloop 附录 引言 为什么想起来要讨论...

  • RunLoop

    概念 数据结构 事件循环机制 RunLoop 与 NSTimer RunLoop 与多线程 一、概念 RunLoo...

  • [iOS面试]第7章 RunLoop相关面试问题

    本文主讲RunLoop相关面试问题,包括RunLoop概念、数据结构、事件循环机制、RunLoop与NSTimer...

  • ZJYiOS学习规划

    一、runloop 1.runloop与线程之间的关系 2.runloop的启动模式与NSTimer使用时候的注意...

  • NSTimer、CADisplayLink、GCD定时器

    一、NSTimer NSTimer和CADisplayLink依赖于RunLoop,如果RunLoop的任务过于繁...

  • iOS-RunLoop

    本文主要内容: 概念 数据结构 事件循环的实现机制 RunLoop与NSTimer RunLoop与线程 源码 一...

  • Runloop 与 NSTimer

    一、Runloop 1、作用1.保持程序运行2.处理app的各种事件(比如触摸,定时器等等)3.节省CPU资源,提...

网友评论

      本文标题:RunLoop与NSTimer

      本文链接:https://www.haomeiwen.com/subject/ywmhrctx.html