iOS events in the appropriate way

Source: Internet
Author: User


recent work has found that the foundation is not very reliable. A good way to solidify the response to an iOS event is needed. Start by tapping the screen with your finger from the simplest user.


In fact, summed up is a sentence: The event will be passed from the bottom view of the window to find a view that can respond to the event, and find the object of the response, you need to look down to the end can be processed by the object ~


If the finger taps the screen, an event (uievent) is generated, and the event is placed in an event queue managed by the uiapplication. The uiapplication is responsible for distributing the incident. First, the event will be distributed to UIWindow. The window then looks in all of its own view to find the most appropriate view for that event. All the view in this process will call Hittest:withevent: method. And in order to start from the bottom of the parent view gradually to the top of the subview to find, know that the last hittest:withevent: return Yes and pointinside:withevent: Yes child view.

and before window passes the event to view, it checks to see if there is a uigesturerecognizer corresponding to the event. If so, use the target of recognizer instead of checking all of the child view.


If there is no recognizer, the corresponding view is found (this view is called Responder object). This is the touches series method that invokes the corresponding response of the view

TouchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:touchesCancelled:withEvent:

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

Where touches contains elements that are objects of the Uitouch class. The count of touches is the number of dots currently touching on the screen.

The Uitouch class has the following 5 properties:

window : The window in which the touch is generated is not necessarily the first window because the window may change.

View: The view at which the touch occurs. Because the view can change, the current view is not necessarily the original view. Tapcount: The number of taps (taps) in a short time, can be judged by Tapcount click, double tap or more. TimeStamp: Time Stamp records the time when a touch event has occurred or changed. Unit is seconds. phase: Touch events have a cycle on the screen, i.e. touch start, touch point movement, end of touch, cancel halfway. The phase lets you see the status of the current touch event in a cycle. Uitouchphase enumeration:     

Uitouchphasebegan

Uitouchphasemoved

Uitouchphasestationary

uitouchphaseended

Uitouchphasecancelled

At this point, if we find that responder object cannot handle the event, it is passed up the event response chain of the object, knowing that the object can be found in response to the event.


This article refers to the following three blog posts, the author of the three blog thanks!


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

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

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

How events for iOS are appropriate

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.