Runloop学习

2017-08-29  本文已影响8人  Django_Monstar

苹果官方的简介:

The programmatic interface to objects that manage input sources.

为对象设计的用于管理输入源的编程接口

A NSRunLoop object processes input for sources such as mouse and keyboard events from the window system, NSPort objects,and NSConnection objects.A NSRunLoop object also processes NSTimerevents.

一个runloop可以处理各种输入源信息 包括 鼠标、键盘、通信 、网络等。一个runloop也可以处理timer事件

Your application neither creates or explicitly manages NSRunLoop objects. Each NSThread object—including the application’s main thread—has an NSRunLoop object automatically created for it as needed. If you need to access the current thread’s run loop, you do so with the class method currentRunLoop.

你不必创建或管理runloop对象,每个线程包括主线程都根据需要自动创建runloop,如果你想使用当前线程的runloop,可以通过类方法 currentRunloop获得

runloop没有初始化方法 默认就会随着线程产生

Note that from the perspective of NSRunLoop, [NSTimer
] objects are not "input"—they are a special type, and one of the things that means is that they do not cause the run loop to return when they fire.

请注意,从NSRunLoop的角度来看,NSTimer对象不是“输入”——是一种特殊类型,runloop不会因为timer开启而返回

常见问题:轮播时timer失效

NSTimer 默认的NSTimer为NSDefaultRunLoopMode,在轮播时触摸屏幕,NSTimer会失效,系统优先响应UI事件,如果想NSTimer正常运行需要改为UITrackingRunLoopMode或者NSRunLoopCommonModes(两种模式)

总结ibireme博客的笔记

RunLoop.png
上一篇下一篇

猜你喜欢

热点阅读