If a UIView is associated with multiple UIGestureRecognizer, a strange problem occurs, as shown in the following code:
[Cpp]
UIPanGestureRecognizer * pang = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (panned :)];
[Self. view addGestureRecognizer: pang];
UISwipeGestureRecognizer * swip = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swip :)];
[Self. view addGestureRecognizer: swip];
-(Void) swip :( UISwipeGestureRecognizer *) gesture {
NSLog (@ "swip ");
}
-(Void) panned :( UIPanGestureRecognizer *) gesture {
NSLog (@ "pan ");
}
UIPanGestureRecognizer * pang = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (panned :)];
[Self. view addGestureRecognizer: pang];
UISwipeGestureRecognizer * swip = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swip :)];
[Self. view addGestureRecognizer: swip];
-(Void) swip :( UISwipeGestureRecognizer *) gesture {
NSLog (@ "swip ");
}
-(Void) panned :( UIPanGestureRecognizer *) gesture {
NSLog (@ "pan ");
}
The result is that the swip gesture is not visible.
The reason is that the system event is passed. When there is a sound, the event will not be passed.
To use both gesturerecognizer, you only need to add a few lines of code.
[Cpp]
Swip. delegate = self;
Swip. delegate = self;
Then, YES is returned, indicating that otherGestureRecognizer is also returned.
[Cpp]
-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer author :( UIGestureRecognizer *) otherGestureRecognizer {
Return YES;
}
-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer author :( UIGestureRecognizer *) otherGestureRecognizer {
Return YES;
}
Now we can see that swip is printed in consol.