简体   繁体   English

即使我强加布尔值也总是假的

[英]Boolean is always false even if I impose true

I have a UIView where before I use UILongPressGestureRecognizer and then I use UIPanGestureRecognizer. 我有一个UIView,在使用UILongPressGestureRecognizer之前,然后使用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. 向UIPanGestureRecognizer发出有关UILongPressGestureRecognizer压力的消息,但我的应用程序不采用布尔值,即使我强加为真,也总是错误的。 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 . 我怀疑panGesture总是在longGesture之前longGesture Maybe the pan recognizer is cancelling long press recognizer entirely. 也许平底锅识别器正在完全取消长按识别器。

You should check what happens by adding more NSLog statements. 您应该通过添加更多NSLog语句来检查会发生什么。


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM