简体   繁体   中英

Gesture Recognizer

I have a UIView on some part of screen. This UIView has Pan gesture recognizer. This UIView ( mainVw) has a UITextView that completely covers the UIView. This UITextview has swipe gestures(left and write).

My problem is When I swipe left or right, The UIView starts dragging also. What I want is ,when I drag the UIView it should drag and when I swipe UITextView should swipe left write but no dragging.

Here is the code I'm using to give better understanding:

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
    [panGesture setMinimumNumberOfTouches:1];
    panGesture.delegate =(id)self;
    [self.mainVw addGestureRecognizer:panGesture];
    //[self.mainVw.layer setValue:[NSValue valueWithCGPoint:vwCaptionBg.center] forKey:@"originalCenter"];


UISwipeGestureRecognizer *rightRecognizer;
rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanTouch:)];
[rightRecognizer setDirection: UISwipeGestureRecognizerDirectionRight];
rightRecognizer.delegate=(id)self;
[self.txtVw addGestureRecognizer:rightRecognizer];


UISwipeGestureRecognizer *vwLeftRecognizer;
vwLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanTouch:)];
[vwLeftRecognizer setDirection: UISwipeGestureRecognizerDirectionLeft];
vwLeftRecognizer.delegate=(id)self;
[self.txtVw addGestureRecognizer:vwLeftRecognizer];

You could try using the [GESTURE requireGestureRecognizerToFail:GESTURE_TO_FAIL]; method. This would be your swipes would need to fail before the pan would be allowed to proceed.

There is also delegate methods you can use for simultaneous gestures.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

Or you could use either of these delegate methods with your own logic.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM