iOS_RunLoop_CFRunLoopMode

2023-12-18  本文已影响0人  萧修
typedef struct __CFRunLoopMode *CFRunLoopModeRef;

struct __CFRunLoopMode {
    CFRuntimeBase _base;
    pthread_mutex_t _lock;  /* must have the run loop locked before locking this */
    CFStringRef _name;
    Boolean _stopped;
    char _padding[3];
    CFMutableSetRef _sources0;
    CFMutableSetRef _sources1;
    CFMutableArrayRef _observers;
    CFMutableArrayRef _timers;
    CFMutableDictionaryRef _portToV1SourceMap;
    __CFPortSet _portSet;
    CFIndex _observerMask;
#if USE_DISPATCH_SOURCE_FOR_TIMERS
    dispatch_source_t _timerSource;
    dispatch_queue_t _queue;
    Boolean _timerFired; // set to true by the source when a timer has fired
    Boolean _dispatchTimerArmed;
#endif
#if USE_MK_TIMER_TOO
    mach_port_t _timerPort;
    Boolean _mkTimerArmed;
#endif
#if DEPLOYMENT_TARGET_WINDOWS
    DWORD _msgQMask;
    void (*_msgPump)(void);
#endif
    uint64_t _timerSoftDeadline; /* TSR */
    uint64_t _timerHardDeadline; /* TSR */
};

__CFRunLoopMode中有一下成员变量,其中_sources0为用户主动发出的事件,_sources1为非用户主动发出的事件

CFMutableSetRef _sources0;
CFMutableSetRef _sources1;
CFMutableArrayRef _observers;
CFMutableArrayRef _timers;

NSDefaultRunLoopMode:默认模式,通常主线程在这个模式下运行。

UITrackingRunLoopMode:只有被触摸才能唤醒,唤醒之后其他事件暂停。
当界面滑动切换到这个mode,保证滑动的时候不受其他mode影响。因此所有影响主线程UI滑动的操作,都放到默认模式default下,比如网络加载回来的图片到tabView的imageView上,更新网络请求回来的数据到tab的数据源。

UIInitializationRunLoopMode:在刚启动app时,进入的第一个mode,启动完成就不再使用。

GSEventReceiveRunLoopMode:接受系统内部事件,通常用不到。

NSRunLoopCommonModes:不是一个真正的模式,占位模式。是滚动模式/默认模式,可处理滚动相关事件。如果将事件源添加到此模式中,就相当于在default和trackmode都添加了这个事件源,在两种模式下运行循环,都会执行该事件源。

上一篇 下一篇

猜你喜欢

热点阅读