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

时间:2012-05-23 11:41:31

标签: iphone objective-c boolean uigesturerecognizer uipangesturerecognizer

我有一个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");
  }

提前致谢

1 个答案:

答案 0 :(得分:0)

当您触摸视图并立即检查移动时,会立即触发平移识别器。长按识别器总是在很长时间后触发平移识别器(在周期结束后)。我怀疑在panGesture之前总是调用longGesture。也许pan识别器完全取消了长按识别器。

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