【问题标题】:Boolean is always false even if I impose true即使我强加为真,布尔值也总是假的
【发布时间】:2012-05-23 11:41:30
【问题描述】:

我有一个 UIView,在我使用 UILongPressGestureRecognizer 之前,我使用 UIPanGestureRecognizer。对于 UIPanGestureRecognizer,我收到一条关于 UILongPressGestureRecognizer 压力的消息,但我的应用程序不采用布尔值,即使我强加为真,这也总是假的。我该怎么办?

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

提前致谢

【问题讨论】:

    标签: iphone objective-c boolean uigesturerecognizer uipangesturerecognizer


    【解决方案1】:

    当您触摸视图并检查从那一刻起的移动时,平移识别器会立即触发。长按识别器触发总是晚于平移识别器(在 long 周期结束之后)。我怀疑panGesture 总是在longGesture 之前调用。也许平移识别器正在完全取消长按识别器。

    您应该通过添加更多 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");
    }
    

    【讨论】:

    • 长手势开始 = YES;长手势结束 = 否;平移手势 =NO;
    • 嗯,这告诉了你想知道的一切。平移是在长手势之后处理的,甚至可能取消长手势。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 2017-09-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多