简体   繁体   中英

Boolean is always false even if I impose true

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

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");
}

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