Generally, all responders which perform custom press handling should override all four of these methods. For each call to the pressesBegan:withEvent:
method, your responder’s pressesEnded:withEvent:
or pressesCancelled:withEvent:
method is called. The pressesChanged:withEvent:
-
Sent to the receiver when a physical button is pressed in the associated view.
Declaration
SWIFT
func pressesBegan(_
presses
: Set<UIPress>,
withEventevent
: UIPressesEvent?)OBJECTIVE-C
- (void)pressesBegan:(NSSet<UIPress *> *)
presses
withEvent:(UIPressesEvent *)
event
Parameters
presses
A set of
UIPress
instances in the event represented byevent
that represent the touches in theUIPressPhaseBegan
phase.event
A
UIPressesEvent
object representing the event to which the presses belong.Availability
Available in iOS 9.0 and later.
-
Sent to the receiver when a system event (such as a low-memory warning) cancels a press event.
Declaration
SWIFT
func pressesCancelled(_
presses
: Set<UIPress>,
withEventevent
: UIPressesEvent?)OBJECTIVE-C
- (void)pressesCancelled:(NSSet<UIPress *> *)
presses
withEvent:(UIPressesEvent *)
event
Parameters
presses
A set of
UIPress
instances in the event represented byevent
that represent the touches in theUIPressPhaseCancelled
phase.event
A
UIPressesEvent
object representing the event to which the presses belong.Discussion
If your app handles other press events, you must also handle cancelled press events. Failure to do so is very likely to lead to incorrect behavior or crashes.
Availability
Available in iOS 9.0 and later.
-
Sent to the receiver when the
force
of the press has changed in the associated view.Declaration
SWIFT
func pressesChanged(_
presses
: Set<UIPress>,
withEventevent
: UIPressesEvent?)OBJECTIVE-C
- (void)pressesChanged:(NSSet<UIPress *> *)
presses
withEvent:(UIPressesEvent *)
event
Parameters
presses
A set of
UIPress
instances in the event represented byevent
that represent the touches in theUIPressPhaseChanged
phase.event
A
UIPressesEvent
object representing the event to which the presses belong.Discussion
The
pressesChanged:withEvent:
method is invoked for presses that provide an analog value, such as thumbsticks or analog push buttons.Availability
Available in iOS 9.0 and later.
-
Sent to the receiver when a button is released from the associated view.
Declaration
SWIFT
func pressesEnded(_
presses
: Set<UIPress>,
withEventevent
: UIPressesEvent?)OBJECTIVE-C
- (void)pressesEnded:(NSSet<UIPress *> *)
presses
withEvent:(UIPressesEvent *)
event
Parameters
presses
A set of
UIPress
instances in the event represented byevent
that represent the touches in theUIPressPhaseEnded
phase.event
A
UIPressesEvent
object representing the event to which the presses belong.Availability
Available in iOS 9.0 and later.