Interacting with other user interface controls
Uicontrol subclasses will overwrite Parentview's gesture. For example, when a user clicks on UIButton, UIButton accepts a touch event, and its parentview is not received. This applies only to the control of the default action for gesture recognition overlap, including:
- One finger click action: UIButton, Uiswitch, Uistepper, Uisegmentedcontrol, and Uipagecontrol.
- One finger rub touch action: UISlider
- One finger drag action: Uiswitch
Events with multi-touch
In iOS, touch refers to a finger sliding and moving on the screen. A gesture is one or more fingers, and its class is a Uitouch object. Multi-touch events are uieventtypetouches
When touch occurs, the following methods are triggered:
- Touchesbegan:withevent: Occurs when touching the screen
- Touchesmoved:withevent: Occurs when the finger moves on the screen
- Touchesended:withevent: Occurs when touch ends, that is, when the finger leaves the screen
- Touchescancelled:withevent: Occurs when Touch is canceled by the system, and the touch is canceled if a phone is available
Change the default event delivery order
You can change the default event pass by changing the properties of the Uigesturerecognizer subclass.
- @property (nonatomic) BOOL Delaystouchesbegan; Default is NO. Causes all-touch events to is delivered to the target view only after this gesture have failed recognition. Set-to-YES-prevent views from processing any touches, that is, recognized as part of this gesture
- @property (nonatomic) BOOL delaystouchesended; Default is YES. Causes touchesended events to is delivered to the target view only after this gesture have failed recognition. This ensures, a touch that's part of the gesture can being cancelled if the gesture is recognized
If a gesture recognizer detects a touch that does not belong to it, it sends the gesture directly to its view, and the ignoretouch:forevent is called: The method is passed directly to the view.
To create a custom gesture recognizer step
- To create a subclass of Uigesturerecognizer
- #import <UIKit/UIGestureRecognizerSubclass.h>
- The following methods are overloaded in sub-classes
1.-(void) reset;2.-(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event;3.-(void) Touchesmoved: (Nsset *) touches withevent: (Uievent *) event;4.-(void) touchesended: (Nsset *) touches withevent: (UIEvent * ) event;5.-(void) touchescancelled: (Nsset *) touches withevent: (Uievent *) event;