iosui-Event Handling

Source: Internet
Author: User

the generation and delivery of eventshow are events generated and delivered?
uiapplication.       2.UIApplication will remove the first event from the event queue and give main window window.       
      1. Event cannot be handled when user interaction is not received          userinteractionenabled = no       2. Cannot receive events when a control is hidden Span style= "color: #008f00;" >          hidden = yes when       3. When a control is transparent, it is not able to receive events            Note: Uiimageview's userinteractionenabled default is no, Span style= "color: #008f00;" >          so Uiimageview and its child controls are not allowed to receive touch events by default
HitTest Method
Role: Find the most suitable view
Parameters: The point at which the current finger is located. Events generated
Return value: Returns who, who is the most suitable view.
When to call: Whenever an event is passed to a control, the HitTest method of the control is called
-(UIView *) HitTest: (cgpoint) point withevent: ( Uievent *) Event
Pointinside Method
Function: Determine if point is not on the method caller
Point: Must be the coordinate system of the method caller
When to call: The HitTest method is called at the bottom of the method, and the point is not on the control.
-(BOOL) Pointinside: (cgpoint) point withevent: (Uievent *) event{
return YES;
}
HitTest Method Bottom -level implementationfunction : This method is called when an event is passed to the current View . The point of the current finger on the screenevents that are currently being generated
-(UIView *) HitTest: (cgpoint) point withevent: (Uievent *)Event{   //1. See if you can receive events    if(self.userinteractionenabled = = NO | | self.hidden = = YES | | Self.alpha <=0.01){        returnNil; }   //2. Judging the current point is not on their own.    if(! [Self pointinside:point withevent:Event]){        returnNil; }   //See if you are the most suitable view//Traverse your own sub-controller from back to forward.    intCount = (int) Self.subviews.count;  for(inti = count-1; I >=0; i--) {       //Remove the child controller.UIView *childview =Self.subviews[i]; //to convert the current point to a coordinate point on a child control.Cgpoint CHILDP =[self convertpoint:point toview:childview]; UIView*view = [Childview hittest:childp withevent:Event]; //If there is a value, return directly, the most appropriate view is returned.        if(view) {returnview; }    }    //did not find a more suitable view than oneself is the most suitable view    returnSelf ;}
response of the eventevent Response and process
A touch event that occurs after a user taps the screen and, after a series of passes, finds the most appropriate view control to handle the event.
Once the most appropriate view control is found, the touches method of the control is called to do the specific event handling
. The default approach for these touches methods is to pass the event up the responder chain, Handing the event to the previous responder for processing
What is the responder chain, the responder object
is a chain of multiple responder objects connected together. inherits the Uiresponder object we call the responder object, which is the object that can handle the event .
the complete process of event delivery and response
When an event is generated, the event is added to an event queue managed by the uiapplication.
UIApplication takes the first event from the event queue and passes it to the main window that sends the event to the application.
The main window calls the HitTest method to find the most appropriate view control, and when found, invokes the touches method of the view control to do something specific.
When the touches method is called, its default practice
is to pass the event along the responder chain to the previous responder, and then invoke the touches method of the previous responder
how to find the last responder
1. If the current view is a view of the controller, then the controller is the last responder.
2. If the current view is not a view of the controller, then its parent control is the previous responder.
3. In the top-most view of the view hierarchy, if the received event or message cannot be processed, it passes the event or message to the Window object for processing
4. If the Window object is not processed, it passes an event or message to the UIApplication object
5. If uiapplication cannot process the event or message, discard it
the complete process of event delivery
1. First pass the event object from top to bottom (passed by the parent control to the child control ), and find the most appropriate control to handle the event. 2. call the touches of the most appropriate control ... . method 3. If you call [Super touches ....]; Will pass the event along the responder chain to the previous responder 4. The last responder's touches is then called ... . method

iosui-Event Handling

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.