main Runloop

1.An app’s main run loop processes all user-related events

2.The UIApplication object sets up the main run loop at launch time and uses it to process events and handle updates to view-based interfaces.

3. the main run loop executes on the app’s main thread

 

过程:screen touch -->system -->through a special port set up by UIKit to app -->Events are queued internally by the app and dispatched one-by-one to the main run loop for execution.

The UIApplication object is the first object to receive the event and make the decision about what needs to be done. 

A touch event is usually dispatched to the main window object, which in turn dispatches it to the view in which the touch occurred. Other events might take slightly different paths through various app objects.

 事件类型:

大多数事件使用main run loop,

how to handle most types of events—including touch, remote control, motion, accelerometer, and gyroscopic events—see Event Handling Guide for iOS.

Event type

Delivered to…

Notes

Touch

The view object in which the event occurred

Views are responder objects. Any touch events not handled by the view are forwarded down the responder chain for processing.

Remote control

Shake motion events

First responder object

Remote control events are for controlling media playback and are generated by headphones and other accessories.

Accelerometer

Magnetometer

Gyroscope

The object you designate

Events related to the accelerometer, magnetometer, and gyroscope hardware are delivered to the object you designate.

Location

The object you designate

You register to receive location events using the Core Location framework. For more information about using Core Location, see Location and Maps Programming Guide.

Redraw

The view that needs the update

Redraw events do not involve an event object but are simply calls to the view to draw itself. The drawing architecture for iOS is described in Drawing and Printing Guide for iOS.

 

 

Some events, such as touch and remote control events, are handled by your app’s responder objects. Responder objects are everywhere in your app. (The UIApplication object, your view objects, and your view controller objects are all examples of responder objects.) Most events target a specific responder object but can be passed to other responder objects (via the responder chain) if needed to handle an event. For example, a view that does not handle an event can pass the event to its superview or to a view controller

 

Touch events occurring in controls (such as buttons) are handled differently than touch events occurring in many other types of views. There are typically only a limited number of interactions possible with a control, and so those interactions are repackaged into action messages and delivered to an appropriate target object. This target-action design pattern makes it easy to use controls to trigger the execution of custom code in your app.

 

 

posted on 2016-05-31 21:43  cocoabanana  阅读(222)  评论(0编辑  收藏  举报

导航