Touches, Presses, and Gestures
Encapsulate your app's event-handling logic in gesture recognizers so that you can reuse that code throughout your app.
--将app的事件处理逻辑封装在手势识别器中,以便可以在整个app中重用该代码。
Overview
If you build your apps using standard UIKit views and controls, UIKit automatically handles touch events (including Multitouch events) for you. However, if you use custom views to display your content, you must handle all touch events that occur in your views. There are two ways to handle touch events yourself.
--如果您使用标准的UIKit视图和控件构建应用程序,UIKit会自动为您处理触摸事件(包括多点触摸事件)。但是,如果使用自定义视图显示内容,则必须处理视图中发生的所有触摸事件。有两种方法可以自己处理触摸事件。
-
Use gesture recognizers to track the touches; see Handling UIKit Gestures.
--使用手势识别器来跟踪触摸事件,参考超链接:处理UIKit的手势 -
Track the touches directly in your
UIView
subclass; see Handling Touches in Your View.
--直接在UIView子类中跟踪触摸;请参见超链接:在视图中处理触摸
Topics --专题
First Steps --第一步
Using Responders and the Responder Chain to Handle Events --使用在响应者链中的响应者来响应事件
Learn how to handle events that propagate through your app.
class UIResponder
--响应者类
An abstract interface for responding to and handling events.
class UIEvent
--时间类
An object that describes a single user interaction with your app.
Touches --触摸
Use touch events directly on a view subclass if touch handling is intricately linked to the view's content.
Handling Input from Apple Pencil
Learn how to detect and respond to touches from Apple Pencil.
Tracking the Force of 3D Touch Events
Manipulate your content based on the force of touches.
Illustrating the Force, Altitude, and Azimuth Properties of Touch Input
Capture Apple Pencil and touch input in views.
Leveraging Touch Input for Drawing Apps
Capture touches as a series of strokes and render them efficiently on a drawing canvas.
An object representing the location, size, movement, and force of a touch occurring on the screen.
Button Presses --按钮按压
An object that represents the presence or movement of a button press on the screen for a particular event.
An event that describes the state of a set of physical buttons that are available to the device, such as those on an associated remote or game controller.
Standard Gestures --标准手势
Use gesture recognizers to simplify touch handling and create a consistent user experience.
Coordinating Multiple Gesture Recognizers
Discover how to use multiple gesture recognizers on the same view.
class UIHoverGestureRecognizer
A gesture recognizer that looks for pointer movement over a view.
class UILongPressGestureRecognizer
A concrete subclass of UIGestureRecognizer
that looks for long-press gestures.
A concrete subclass of UIGestureRecognizer
that looks for panning (dragging) gestures.
class UIPinchGestureRecognizer
A concrete subclass of UIGestureRecognizer
that looks for pinching gestures involving two touches.
class UIRotationGestureRecognizer
A concrete subclass of UIGestureRecognizer
that looks for rotation gestures involving two touches.
class UIScreenEdgePanGestureRecognizer
A gesture recognizer that looks for panning (dragging) gestures that start near an edge of the screen.
class UISwipeGestureRecognizer
A concrete subclass of UIGestureRecognizer
that looks for swiping gestures in one or more directions.
A concrete subclass of UIGestureRecognizer
that looks for single or multiple taps.
Custom Gestures --用户自定义手势
Implementing a Custom Gesture Recognizer
Discover when and how to build your own gesture recognizers
The base class for concrete gesture recognizers.
protocol UIGestureRecognizerDelegate
A set of methods implemented by the delegate of a gesture recognizer to fine-tune an app’s gesture-recognition behavior.
3D Touch Interactions --3D触摸交互
A class that registers a view to provide a custom user experience in response to 3D Touch interactions.
protocol UIPreviewInteractionDelegate
A set of methods for communicating the progress of a preview interaction.
A set of methods that defines the styles you can apply to peek quick actions and peek quick action groups, and defines a read-only accessor for the user-visible title of a peek quick action.
See Also
User Interactions
Bring drag and drop to your app by using interaction APIs with your views.
Support pointer interactions in your custom controls and views.
Handle double-tap user interactions on Apple Pencil.
Navigate the interface of your UIKit app using a remote or a game controller.
Simplify interactions with your app using menu systems, contextual menus, Home screen quick actions, and keyboard shortcuts.
Make your apps accessible to everyone, including people with disabilities.