0

我正在为 iPad 开发一个 iOS6 应用程序。我编写了 UITextField 的子类,它使用户能够在视图周围拖动、捏合和旋转字段。问题是如果你在没有旋转的情况下捏住字段,完成手势后,它会进入编辑模式。这不应该发生,我添加了一些禁用它的行,但它并没有停止。这是我的代码:

- (BOOL) canBecomeFirstResponder{
if (gesturing==YES) {
       return NO;
}else  return YES;
}


 - (void) tapDetected:(UITapGestureRecognizer*) pinchRecognizer {

if (gesturing==NO) {
    [self becomeFirstResponder];
}
}


- (void) pinchDetected:(UIPinchGestureRecognizer*) pinchRecognizer {

CGFloat scale = pinchRecognizer.scale;
self.font = [self.font fontWithSize:self.font.pointSize*(scale)];


//self.transform = CGAffineTransformScale(self.transform, scale, scale);

[self sizeToFit];


pinchRecognizer.scale = 1.0;

if (pinchRecognizer.state == UIGestureRecognizerStateChanged) {
    gesturing =YES;   

}

if (pinchRecognizer.state == UIGestureRecognizerStateBegan) {
    gesturing =YES;

}

if (pinchRecognizer.state == UIGestureRecognizerStateEnded) {
    gesturing =NO;

}


 }


- (void) panDetected:(UIPanGestureRecognizer *)panRecognizer {

CGPoint translation = [panRecognizer translationInView:self.superview];
CGPoint imageViewPosition = self.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;

self.center = imageViewPosition;
[panRecognizer setTranslation:CGPointZero inView: self.superview];



if (panRecognizer.state == UIGestureRecognizerStateChanged) {
    gesturing=YES;       

}

if (panRecognizer.state == UIGestureRecognizerStateEnded) {
    gesturing=NO;



}


  }


 - (void) rotationDetected:(UIRotationGestureRecognizer *)rotationRecognizer{  


CGFloat angle = rotationRecognizer.rotation;
self.transform = CGAffineTransformRotate(self.transform, angle);
rotationRecognizer.rotation = 0.0;

if (rotationRecognizer.state == UIGestureRecognizerStateChanged) {

    gesturing = YES;
}

if (rotationRecognizer.state == UIGestureRecognizerStateEnded) {

    gesturing = NO;
}

 }


- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
     }
4

1 回答 1

1

我的默认值为gesturingNO如果您不将其初始化为YES. 是否已调试并弄清楚每当您尝试应用时首先检测到哪个手势识别器pinch

您支持同时手势识别,因此当您应用时pinch,您的手指触摸可能会被检测为pan. 如果是这种情况,则方法中的if(gesturing == NO)条件tapDetected:得到满足,您的 textField 将成为第一响应者。

于 2013-06-17T15:57:29.193 回答