An analysis of IOS Runloop two

Source: Internet
Author: User

The last one we said Runloop several models, then we in the pattern to do what???

There are three modules in the mode:

Event source (input source) source

Source:

Sort by official documents

Port-based

Custom Input

Cocoa Perform Selector

According to the function call stack, the source classification

SOURCE0: Not Port-based

Source1: Port-based, communicates through the kernel and other threads, accepts, distributes system events.

(There is nothing much to use, the remaining source concept I will not introduce the interest can be found elsewhere)

Viewer Observer

The observer's role is to listen to the state being executed in the Runloop.

The status has the following several

The status of the listening:

Kcfrunloopentry = (1UL << 0), 1

Kcfrunloopbeforetimers = (1UL << 1), 2

Kcfrunloopbeforesources = (1UL << 2), 4

kcfrunloopbeforewaiting = (1UL << 5), 32

kcfrunloopafterwaiting = (1UL << 6), 64

Kcfrunloopexit = (1UL << 7), 128

Kcfrunloopallactivities = 0x0fffffffu

We can choose to listen to different States to implement different operations.

The following code is the implementation of heaven all States

viewcontroller.m//CX runloop Analysis////Created by Ma C on 16/3/29.//Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void ) Viewdidload {[Super viewdidload];} -(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{//Add observe/* status monitored Kcfrunlo Opentry = (1UL << 0), 1 kcfrunloopbeforetimers = (1UL << 1), 2 kcfrunloopbeforesources = (1UL <&l T 2), 4 kcfrunloopbeforewaiting = (1UL << 5), kcfrunloopafterwaiting = (1UL << 6), Kcfrunlo Opexit = (1UL << 7), kcfrunloopallactivities = 0x0fffffffu */cfrunloopobserverref observe = Cfrunlo Opobservercreatewithhandler (Cfallocatorgetdefault (), kcfrunloopallactivities, YES, 0, ^ (cfrunloopobserverref            Observer, cfrunloopactivity activity) {NSLog (@ "Hear runloop--%zd", activity);    }); Add Observer CfrunloopaddobseRVer (Cfrunloopgetcurrent (), observe, Kcfrunloopdefaultmode);} @end

The demo effect is:

Careful observation is not difficult to find when running to the end when I am not in action, the log stops printing.

What is this for??? Look closely at all States and know that because it is dormant.

To prove this view we have been clicking on the screen to test it.

(The output of 32 after the test results is actually not logical because I have been * quick * click.) )

(normal condition should appear 64 etc.)

Because no other state exists, it is always dormant (the process I will introduce in the next article)

Mastering this is a great benefit for development.

Timer Nstimer

Since the first one is simply introduced with a timer, Runloop is therefore not prosecuted here.

Do not see the first article can be at the end of the article click on the previous article.

    

An analysis of IOS Runloop two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.