UIView is associated with multiple Gesture

Source: Internet
Author: User

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.

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.