1

当我的 hitView 部分来自 UIPanGestureRecognizer 之后的超级视图时,UILongPressGestureRecognizer 不起作用。为什么?

   - (id)initWithFrame:(CGRect)frame 
    {
      UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
    [panGesture setMaximumNumberOfTouches:1];
    [panGesture setDelegate:self];
    [_glassesImage addGestureRecognizer:panGesture];


    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(enchance:)];
    longPressGesture.minimumPressDuration = 0.2;
    [_glassesImage addGestureRecognizer:longPressGesture];


    [self addSubview:_glassesImage];
    }



    - (void)enchance:(UILongPressGestureRecognizer *)gestureRecognizer 
   {
        UIView *hitView = [gestureRecognizer view];
        hitView.alpha=0.6;
        inLongPress=YES;
        gestureRecognizer.allowableMovement = 200;

      if ([gestureRecognizer state] == UIGestureRecognizerStateEnded){
        hitView.alpha=1.0;
        inLongPress=NO;

      }
    }
4

2 回答 2

2

尝试为您的手势识别器定义一个委托,然后提供一个实现:

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

参考

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
 }
于 2012-07-02T08:51:24.660 回答
0

将委托添加到 longPressGesture。

longPressGesture.delegate = self;

我想这会对你有所帮助。

于 2012-07-02T09:02:53.817 回答