0

UIView在屏幕的某个部分有一个。这个 UIView 有平移手势识别器。这个 UIView (mainVw) 有一个UITextView完全覆盖 UIView。此 UITextview 具有滑动手势(向左和书写)。

我的问题是当我向左或向右滑动时, UIView 也开始拖动。我想要的是,当我拖动 UIView 时它应该拖动,当我滑动 UITextView 时应该向左滑动写入但不拖动。

这是我用来更好理解的代码:

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];
4

1 回答 1

0

您可以尝试使用该[GESTURE requireGestureRecognizerToFail:GESTURE_TO_FAIL];方法。这将是您的滑动需要失败,然后才能允许平底锅继续进行。

还有一些委托方法可以用于同时手势。

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

或者您可以将这些委托方法中的任何一个与您自己的逻辑一起使用。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
于 2012-09-14T17:43:23.983 回答