屏幕的某些部分有UIView
。这个UIView有Pan手势识别器。这个UIView(mainVw)有一个完全覆盖UIView的UITextView
。此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];
答案 0 :(得分:0)
您可以尝试使用[GESTURE requireGestureRecognizerToFail:GESTURE_TO_FAIL];
方法。这将是您的滑动将需要在允许继续进行平移之前失败。
您还可以使用委托方法进行同步手势。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
或者您可以使用这些委托方法中的任何一种使用您自己的逻辑。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer