original articles, welcome reprint. Reprint Please specify: Dongsheng's blog
The app interacts with the user and relies on a variety of events. An event responder object is an object that can respond to an event and process it, and the responder chain is made up of a series of linked respondents. The responder chain is very important in event handling, and the responder chain can route user events to the correct objects.
Responder object and Response chain
uiresponder is the base class for all responder objects, not only for event handling, but also for the common responder behavior definition programming interface. uiapplication uiview uiwindow uiviewcontroller Span style= "font-family: ' The song Body '; > (and its subclasses) are inherited directly or indirectly from the uiresponder
650) this.width=650; "Width=" "height=" 303 "title=" image1.jpg "style=" width:500px;height:303px; "src="/HTTP/ S4.51cto.com/wyfs02/m00/7d/13/wkiom1bfvkzbkwcsaaj6vn8smqi685.jpg "border=" 0 "vspace=" 0 "hspace=" 0 "alt=" Wkiom1bfvkzbkwcsaaj6vn8smqi685.jpg "/>
The First Responder is the responder object (usually a UIView object) in the application that is currently responsible for receiving touch events . the UIWindow object sends the event as a message to the first responder, giving it an opportunity to handle the event first. If the first responder does not process, the system passes the event (through the message) to the next responder in the responder chain to see if it can be processed.
The responder chain is a series of linked responder objects that allow the responder object to pass responsibility for handling events to other higher-level objects. As the application looks for objects capable of handling events, events are passed up in the responder chain. The responder chain consists of a series of "next responders".
1 . The first responder passes the event to its view controller, if any, and then its parent view.
2 . Similarly, each subsequent view in the view hierarchy is first passed to its view controller, if any, and then its parent view.
3 . The topmost container view passes events to the uiwindow object.
4 . the uiwindow Object passes an event to the uiapplication Singleton object.
Touch events
Touch ( Uitouch ) object represents a touch event on the screen that accesses the touch through uievent object that is passed to the event responder object. Touch objects have both time and space.
1 . Time Aspects
The time aspect information is called the stage ( Phase ), indicating whether the touch has just begun, is moving or is in a stationary state, and when it ends, i.e. when the finger is lifted from the screen.
In a given touch phase, the application sends these messages if a new touch action occurs or an existing touch action changes.
Send touchesbegan:withevent: Message when one or more fingers touch the screen .
Send touchesmoved:withevent: Message when one or more fingers move on the screen .
Send touchesended:withevent: Message when one or more fingers leave the screen .
650) this.width=650; "Width=" "height=" 189 "title=" image2.jpg "style=" WIDTH:500PX;HEIGHT:189PX; "src="/HTTP/ S1.51cto.com/wyfs02/m00/7d/12/wkiol1bfvvhtcfq9aaev0cml2rc039.jpg "border=" 0 "vspace=" 0 "hspace=" 0 "alt=" Wkiol1bfvvhtcfq9aaev0cml2rc039.jpg "/>
2 . Space aspects
The touch point object also includes the current position information in the View or window, as well as the previous location information, if any. The following method is where you can get the position of the touch point in the window or view.
Func Locationinview (_ View:uiview?), Cgpoint
Get location information in the window or view where the previous touch point is located:
Func Previouslocationinview (_view:uiview?), Cgpoint
Welcome to follow Dongsheng Sina Weibo@tony_Dongsheng.
Learn about the latest technical articles, books, tutorials and information on the public platform of the smart Jie classroom
650) this.width=650; "Width=" "height=" "title=" Qrcode_for_gh_ca9759a5ef7f_258.jpg "style=" width:150px;height : 150px; "src=" http://s4.51cto.com/wyfs02/M02/7D/13/wKiom1bfvOSCd03ZAADC6S3kNXs954.jpg "border=" 0 "vspace=" 0 " Hspace= "0" alt= "wkiom1bfvoscd03zaadc6s3knxs954.jpg"/>
More ProductsIOS,Cocos, mobile Design course please pay attention to the official website of Chi Jie Classroom:http://www.zhijieketang.com
Smart-Jie Classroom Forum Website:http://51work6.com/forum.php
This article is from the "Dongsheng-ios Technical Consultant" blog, make sure to keep this source http://tonyguan.blog.51cto.com/701759/1749103
"Learn Swift from scratch" learning notes (day)--cocoa Touch design mode and application of the responder chain and touch events