简体   繁体   中英

UILongPressGestureRecognizer don't work after the use of a UIPanGestureRecognizer

When my hitView comes partially from the superview after a UIPanGestureRecognizer, the UILongPressGestureRecognizer don't work. Why?

   - (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;

      }
    }

Try defining a delegate for your gesture recognizers and then provide an implementation for:

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

( refs )

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
 }

Add delegate to longPressGesture.

longPressGesture.delegate = self;

I think it will be helpful to you.

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