GestureRecognizer¶
- class pyto_ui.GestureRecognizer(type: GestureType, action: callable = None)¶
A gesture-recognizer object—or, simply, a gesture recognizer—decouples the logic for recognizing a sequence of touches (or other input) and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.
This class represents the type of gesture passed to the
typeinitializer parameter. SeeGesture Typeconstants for possible values. When the gesture is starting, cancelling or changig,actionis called with the gesture recognizer as parameter. You can then access the location and the state from it.Example:
''' Move a circle with finger. ''' import pyto_ui as ui view = ui.View() view.background_color = ui.SystemColors.SYSTEM_BACKGROUND circle = ui.View() circle.size = (50, 50) circle.center = (view.width/2, view.height/2) circle.flexible_margins = True circle.corner_radius = 25 circle.background_color = ui.COLOR_LABEL view.add_subview(circle) def move(sender: ui.GestureRecognizer): if sender.state == ui.GESTURE_STATE_CHANGED: circle.center = sender.location gesture = ui.GestureRecognizer(ui.GESTURE_TYPE_PAN) gesture.action = move view.add_gesture_recognizer(gesture) ui.show_view(view)
- property action: callable¶
A function called to handle the gesture. Takes the sender gesture recognizer as parameter.
- Return type:
callable
- property allowedTouchTypes: tuple[TouchType]¶
An array of touch types used to distinguish type of touches. For possible values, see
Touch Typeconstants.- Return type:
list of
Touch Type
- property allowed_touch_types: tuple[TouchType]¶
An array of touch types used to distinguish type of touches. For possible values, see
Touch Typeconstants.- Return type:
list of
Touch Type
- property cancels_touches_in_view: bool¶
A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.
- Return type:
bool
- property delays_touches_began: bool¶
A Boolean value determining whether the receiver delays sending touches in a begin phase to its view.
- Return type:
bool
- property delays_touches_ended: bool¶
A Boolean value determining whether the receiver delays sending touches in a end phase to its view.
- Return type:
bool
- property enabled: bool¶
A boolean indicating whether the gesture recognizer is enabled.
- Return type:
bool
- property location: tuple[float, float]¶
(Read Only) Returns a tuple with the X and the Y position of the gesture in its container view.
- Return type:
tuple[float, float]
- property minimum_press_duration: float¶
The minimum time that the user must press on the view for the gesture to be recognized.
(Only works for long press gestures)
- Return type:
float
- property number_of_touches: int¶
(Read Only) Returns the number of touches involved in the gesture represented by the receiver.
- Return type:
int
- property requires_exclusive_touch_type: bool¶
A Boolean indicating whether the gesture recognizer considers touches of different types simultaneously.
- Return type:
bool
- property state: GestureState¶
(Read Only) The current state of the gesture recognizer.
- Return type:
Gesture State
- property x: float¶
(Read Only) Returns the X position of the gesture in its container view.
- Return type:
float
- property y: float¶
(Read Only) Returns the Y position of the gesture in its container view.