Class
UIEvent
An object that describes a single user interaction with your app.
--描述单个用户交互的对象。
Declaration
class UIEvent : NSObject
Overview --概览
Apps can receive many different types of events, including touch events, motion events, remote-control events, and press events. Touch events are the most common and are delivered to the view in which the touch originally occurred. Motion events are UIKit triggered and are separate from the motion events reported by the Core Motion framework. Remote-control events allow a responder object to receive commands from an external accessory or headset so that it can manage manage audio and video—for example, playing a video or skipping to the next audio track. Press events represent interactions with a game controller, AppleTV remote, or other device that has physical buttons. You can determine the type of an event using the type
and subtype
properties.
--app可以接收许多不同类型的事件,包括触摸事件、运动事件、远程控制事件和按下事件。触摸事件是最常见的,它们被传递到触摸最初发生时的所在视图。运动事件是由UIKit触发的,与Core Motion框架报告的运动事件是分开的。远程控制事件允许应答器对象接收来自外部附件或耳机的命令,以便它能够管理音频和视频,例如播放视频或跳到下一个音轨。按下事件表示与游戏控制器、AppleTV遥控器或其他具有物理按钮的设备的交互。可以使用UIEvent的type
and subtype
属性确定事件的类型。
A touch event object contains the touches (that is, the fingers on the screen) that have some relation to the event. A touch event object may contain one or more touches, and each touch is represented by a UITouch
object. When a touch event occurs, the system routes it to the appropriate responder and calls the appropriate method, such as touchesBegan(_:with:)
. The responder then uses the touches to determine an appropriate course of action.
--触摸事件对象包含了与事件有关的若干个触摸(即屏幕上的手指)。一个触摸事件对象可以包含一个或多个触摸,每个触摸都由一个UITouch对象表示。当一个触摸事件发生时,系统将它路由到相应的响应器并调用相应的方法,例如touchesBegan(:with:)。然后响应者使用触摸来决定一个适当的动作过程。
During a multitouch sequence, UIKit reuses the same UIEvent
object when delivering updated touch data to your app. You should never retain an event object or any object returned from an event object. If you need to retain data outside of the responder method you use to process that data, copy that data from the UITouch
or UIEvent
object to your local data structures.
--在多点触控序列中,UIKit会重用相同的UIEvent对象,当向用户app传送更新的触控数据时。你不应保留event对象或从event对象返回的任何对象。如果需要保留响应者方法里面的数据,请从UITouch或UIEvent对象复制该数据到本地数据结构。
For more information on how to handle events in your UIKit app, see Event Handling Guide for UIKit Apps.
Topics --专题
Getting the Touches for an Event --获取事件中的触摸对象
Returns all touches associated with the event.
func touches(for: UIView) -> Set<UITouch>?
Returns the touch objects from the event that belong to the specified given view.
func touches(for: UIWindow) -> Set<UITouch>?
Returns the touch objects from the event that belong to the specified window.
func coalescedTouches(for: UITouch) -> [UITouch]?
Returns all of the touches associated with the specified main touch.
func predictedTouches(for: UITouch) -> [UITouch]?
Returns an array of touches that are predicted to occur for the specified touch.
Getting Event Attributes --获取事件的属性
The time when the event occurred.
Getting the Event Type --获取事件类型
Returns the type of the event.
var subtype: UIEvent.EventSubtype
Returns the subtype of the event.
Getting the Touches for a Gesture Recognizer --获取手势识别器中的触摸对象
func touches(for: UIGestureRecognizer) -> Set<UITouch>?
Returns the touch objects that are being delivered to the specified gesture recognizer.
Constants --常量
Specifies the general type of an event
Specifies the subtype of the event in relation to its general type.
Instance Properties --实例属性
var buttonMask: UIEvent.ButtonMask
var modifierFlags: UIKeyModifierFlags
Structures --数据结构
Relationships
Inherits From
Conforms To
See Also
First Steps
Using Responders and the Responder Chain to Handle Events
Learn how to handle events that propagate through your app.
An abstract interface for responding to and handling events.