我正在为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;
     }

最佳答案

如果没有将其初始化为gesturing,则我默认的NO值为YES。是否调试并弄清楚了何时尝试应用pinch时首先检测到哪个手势识别器?
您支持同时手势识别,因此当您应用pinch时,手指的触摸可能会被检测为pan。如果是这种情况,则if(gesturing == NO)方法中的tapDetected:条件将得到满足,并且您的textField将成为第一响应者。

10-07 19:08