Event Processing in iOS-continuation, ios-Continuation
1. Diagram of iOS event handling process
Here is an overview of the previous article:
Http://blog.csdn.net/supersonico/article/details/46845361
1. When you touch the screen, the operating system will capture the Response Message and put the message into the queue managed by UIApplication.
2. Retrieve the message from UIApplication and send it to UIWindow. UIWindow makes the following judgment:
3. Wait until the most appropriate yellowView is found. At this time, the event is passed over, and then the responder chain is executed in reverse.
4. touch's default practice: do not handle it by yourself, and give it to the last responder. By default, the last responder is the parent control. You can rewrite the touch method to handle the response click event. If the method to be rewritten does not call the method of the parent class, the responder chain ends, and the call continues.
2. Details about the role of hitTest: withEvent: Method 2.1 hitTest: withEvent:
-(UIView) HitTest :( CGPoint) point withEvent :( UIEvent) Event
1. When is hitText called? When an event is passed to a control, the control will call this method.
2. hitText: Find the most appropriate view.
3. Event transfer, UIApplication-> UIWindow. What is the most appropriate view in UIWindow? [UIWindow hitTest: withEvent:] What is done in it?
2.2 implement hitTest: withEvent:
Implementation ideas:
1. Determine whether you can receive events.
2. The judgment point is not in its own window.
3. traverse your child control and find a more appropriate View than yourself
// Point: the position of the touch point on the method caller's coordinate system-(UIView *) hitTest :( CGPoint) point withEvent :( UIEvent *) event {// 1. determine whether or not to receive the touch event if (self. userInteractionEnabled = NO | self. hidden = YES | self. alpha <= 0.0) return nil; // 2. determine if ([self pointInside: point withEvent: event] = NO) return nil; // 3. traverse the child control int count = (int) self from the back. subviews. count; for (int I = count-1; I> = 0; I --) {// retrieve the child control UIView * childView = self. subviews [I]; // converts it to the coordinate system of the Child control. point CGPoint childP = [self convertPoint: point toView: childView]; UIView * fitView = [childView hitTest: childP withEvent: event]; if (fitView) {return fitView;} // It indicates that there is no more appropriate view return self ;}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.