Domanda

I have a UIView where before I use UILongPressGestureRecognizer and then I use UIPanGestureRecognizer. To UIPanGestureRecognizer I get a message about the pressure of UILongPressGestureRecognizer but my app doesn't take the boolean, this is always false even if I impose true. How can I do?

 -(IBAction)longGesture:(UILongPressGestureRecognizer *)gestureRecognizer{


   if(fromRiga ==0){
    if ([gestureRecognizer state]==UIGestureRecognizerStateBegan){
        self.inLongPress = YES;
        self.view.backgroundColor =[UIColor darkGrayColor];
        gestureRecognizer.allowableMovement=200;

      }else if([gestureRecognizer state]==UIGestureRecognizerStateEnded){
        self.inLongPress = NO;
      }
}

 - (IBAction)panGesture:(UIPanGestureRecognizer *)gestureRecognizer
  {
    NSLog(@"inLongPress is %@", self.inLongPress ? @"YES": @"NO");
  }

thanks in advance

È stato utile?

Soluzione

Pan recognizer triggers immediately when you touch the view and checks the movement since that moment. Long press recognizer triggers always much later then pan recognizer (after the long period ends). I suspect that the panGesture is always called before longGesture. Maybe the pan recognizer is cancelling long press recognizer entirely.

You should check what happens by adding more NSLog statements.


-(IBAction)longGesture:(UILongPressGestureRecognizer *)gestureRecognizer {
    NSLog(@"Long gesture");

    if (fromRiga == 0){
        if ([gestureRecognizer state] == UIGestureRecognizerStateBegan){
            self.inLongPress = YES;
            self.view.backgroundColor =[UIColor darkGrayColor];
            gestureRecognizer.allowableMovement=200;

            NSLog(@"Long gesture began, self.iLongPress = %@", self.iLongPress ? @"YES" : @"NO");
        } else if([gestureRecognizer state] == UIGestureRecognizerStateEnded) {
            self.inLongPress = NO;
            NSLog(@"Long gesture ended, self.iLongPress = %@", self.iLongPress ? @"YES" : @"NO");
        }
    }
}

- (IBAction)panGesture:(UIPanGestureRecognizer *)gestureRecognizer {
    NSLog(@"Pan gesture, self.iLongPress = %@", self.iLongPress ? @"YES" : @"NO");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top