If a uiview is associated with multiple uigesturerecognizer, a strange problem occurs, as shown in the following code:
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.
swip.delegate = self;
Then, yes is returned, indicating that othergesturerecognizer is also returned.
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES;}
Now we can see that swip is printed in consol.