IOS event Method

Source: Internet
Author: User

IOS event Method


Recent work has found that the Foundation is not reliable. You need to consolidate the iOS event response methods. The simplest user clicks the screen with his finger.


In fact, it is concluded that the event will be passed up from the bottom view of the window to find the view that can respond to the event, and after the response object is found, we need to look down for objects that can finally process this event ~


If you click the screen with your finger, an event is generated and put into the event queue managed by UIApplication. UIApplication is responsible for distributing this event. First, this event will be distributed to UIWindow. Then, the Window will search for all its views and find the View most suitable for the event. In this process, all views will call the hitTest: WithEvent: method. The sequence is to start from the parent view at the bottom layer to find the subView at the top layer. Find the last hitTest: WithEvent: YES and pointInside: WithEvent: is a child view of YES.

Before the window passes the event to the View, it will check whether there is a UIGestureRecognizer event. If yes, use the target of the recognizer to perform the corresponding action, instead of checking all the child views.


If no recognizer exists, the corresponding view is found (this view is called responder object ). At this time, the touches series method of the corresponding response view will be called.

touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:touchesCancelled:withEvent:

The first parameter of these methods is (NSSet *) touches, and the second parameter is (UIEvent *) event.

Touches contains all the elements of the UITouch class. The count of touches is the number of current touch points on the screen.

The UITouch class has the following five attributes:

Window: the window in which the system is generated. The current window is not necessarily the first one because the window may change.

View: The view in which the touch occurs. Because the view may change, the current view is not necessarily the original view. TapCount: the number of times a tap screen is tapped in a short period of time. You can click, double-click, or click more based on tapCount. TimeStamp: timeStamp records the time when a touch event occurs or changes. The Unit is seconds. Phase: A Touch event has a cycle on the screen, that is, the touch starts, the touch point moves, the touch ends, and the process is canceled midway through. You can use phase to view the status of the current touch event in a cycle. UITouchPhase enumeration:

UITouchPhaseBegan

UITouchPhaseMoved

UITouchPhaseStationary

UITouchPhaseEnded

UITouchPhaseCancelled

At this time, if we find that the responder object cannot process this event, it will be passed up along the Event Response chain of this object, until the object that can respond to this event is found.


I would like to express my gratitude to the authors of the three blogs for their reference!


Http://www.cnblogs.com/Quains/p/3369132.html

Http://www.cnblogs.com/zhw511006/p/3517248.html

Http://www.tuicool.com/articles/ZZJreu

Related Article

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.