美文网首页
iOS RunLoop 相关面试题

iOS RunLoop 相关面试题

作者: 爱吃萝卜的小蘑菇 | 来源:发表于2017-09-07 16:15 被阅读29次
    Paste_Image.png Paste_Image.png

    RunLoop监听

     //创建一个runloop监听者
        CFRunLoopObserverRef observer = CFRunLoopObserverCreateWithHandler(CFAllocatorGetDefault(),kCFRunLoopAllActivities, YES, 0, ^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
    
            NSLog(@"监听runloop状态改变---%zd",activity);
        });
    
        //为runloop添加一个监听者
        CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer, kCFRunLoopDefaultMode);
    
        CFRelease(observer);
    
    //监听的状态
    typedef CF_OPTIONS(CFOptionFlags, CFRunLoopActivity) {
        kCFRunLoopEntry = (1UL << 0),   //即将进入Runloop
        kCFRunLoopBeforeTimers = (1UL << 1),    //即将处理NSTimer
        kCFRunLoopBeforeSources = (1UL << 2),   //即将处理Sources
        kCFRunLoopBeforeWaiting = (1UL << 5),   //即将进入休眠
        kCFRunLoopAfterWaiting = (1UL << 6),    //刚从休眠中唤醒
        kCFRunLoopExit = (1UL << 7),            //即将退出runloop
        kCFRunLoopAllActivities = 0x0FFFFFFFU   //所有状态改变
    };
    

    Runloop运行逻辑

    Runloop运行逻辑 Runloop运行逻辑

    相关文章

      网友评论

          本文标题:iOS RunLoop 相关面试题

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