Event handling in iOS-sequel

Source: Internet
Author: User

1. Diagram of the process of iOS event processing

1. When the screen is touched, the response message is captured by the operating system, and the message is placed into the UIApplication managed queue.
2. Take the message from the uiapplication and give it to Uiwindow,uiwindow to make the following judgments:

    1. Determine if you can receive events
    2. Dot is not on his own window
    3. Traverse your own child controls to find a more appropriate view than yourself
    4. The child control receives, continues the above steps; the child control does not receive, the window handles the event itself

3. Until the most appropriate Yellowview is found, the event is delivered at the end, and then the responder chain is executed in reverse.
4.touch Default Practice: Do not process yourself, to the previous responder. The previous responder defaults to the parent control. You can override the touch method to handle a response click event, overriding the method if the parent class's method is not called, the responder chain ends, and the call continues to go down.

2. Detailed Hittest:withevent: Method 2.1 Hittest:withevent: The Role of

-(UIView ) HitTest: (cgpoint) point withevent: (Uievent ) Event
1. Hittext When to call: When an event is passed to a control, the control calls this method
2. Hittext role: Find the most appropriate view.
3. Event delivery, UIApplication-UIWindow. UIWindow to find the right view? [UIWindow hittest:withevent:] What's going on inside?

    1. Can I tell if the window will handle events? If not, it means that the window is not the most suitable view, and will not look for a more appropriate view than yourself, directly return nil, notify UIApplication, there is no most appropriate view.
    2. Judging points are not in the window
    3. Traverse your own child controls to find out if there is a more appropriate view than yourself
    4. If the child control does not receive an event, it means that the child control does not find the most appropriate view, and then returns nil, telling the window not to find a more appropriate view, and the window knows that there is no more appropriate view for itself to handle the event.
2.2 Implementation Hittest:withevent:

Implementation ideas:
1. Determine if you can receive events
2. Judging points are not on their own window
3. Traverse your own child controls to find a more appropriate view than yourself

//point: Is the location of the touch points on the method caller's coordinate system- (UIView*) HitTest: (Cgpoint) Point withevent: (Uievent *) event{//1. Determine if the touch event can be received    if( Self. userinteractionenabled==NO|| Self. Hidden==YES|| Self. Alpha<=0.0)return Nil;//2. Determine if the next point is not on the control    if([ SelfPointinside:point Withevent:event] = =NO)return Nil;//3. Traverse the child control from back to forward    intCount = (int) Self. Subviews. Count; for(inti = count-1; I >=0; i--) {//Remove the child controls that appear at the front        UIView*childview = Self. Subviews[i];//Convert to a sub-control point on the coordinate system        CgpointCHILDP = [ SelfConvertpoint:point Toview:childview];UIView*fitview = [Childview hittest:childp withevent:event];if(Fitview) {returnFitview; }    }//means there is no more suitable view than yourself    return  Self;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Event handling in iOS-sequel

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.