蘋(píng)果官方的簡(jiǎn)介:
The programmatic interface to objects that manage input sources.
為對(duì)象設(shè)計(jì)的用于管理輸入源的編程接口
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.
一個(gè)runloop可以處理各種輸入源信息 包括 鼠標(biāo)、鍵盤(pán)、通信 、網(wǎng)絡(luò)等。一個(gè)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.
你不必創(chuàng)建或管理runloop對(duì)象,每個(gè)線程包括主線程都根據(jù)需要自動(dòng)創(chuàng)建runloop,如果你想使用當(dāng)前線程的runloop,可以通過(guò)類方法 currentRunloop獲得
runloop沒(méi)有初始化方法 默認(rèn)就會(huì)隨著線程產(chǎn)生
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.
請(qǐng)注意,從NSRunLoop的角度來(lái)看,NSTimer對(duì)象不是“輸入”——是一種特殊類型,runloop不會(huì)因?yàn)閠imer開(kāi)啟而返回
常見(jiàn)問(wèn)題:輪播時(shí)timer失效
NSTimer 默認(rèn)的NSTimer為NSDefaultRunLoopMode,在輪播時(shí)觸摸屏幕,NSTimer會(huì)失效,系統(tǒng)優(yōu)先響應(yīng)UI事件,如果想NSTimer正常運(yùn)行需要改為UITrackingRunLoopMode或者NSRunLoopCommonModes(兩種模式)
總結(jié)ibireme博客的筆記
