3

我正在像这样设置我的识别器。请注意,虽然我将识别器添加到 self.view,但实际上是 self.container 正在被转换(这是一个子视图)。

UIPinchGestureRecognizer *twoFingerPinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingerPinch:)];
twoFingerPinch.delegate = self;
[self.view addGestureRecognizer:twoFingerPinch];

UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotate:)];
rotate.delegate = self;
[self.view addGestureRecognizer:rotate];

捏/缩放本身就可以正常工作:

- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer 
{

CGFloat scale = _lastScale * recognizer.scale;

CGAffineTransform tr = CGAffineTransformScale(self.view.transform, scale, scale);
self.container.transform = tr;

if (recognizer.state == UIGestureRecognizerStateEnded)  {
    _lastScale = scale;
    return;
}
}

但是我很难添加轮换:

- (IBAction)handleRotate:(UIRotationGestureRecognizer *)recognizer {
//recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
//recognizer.rotation = 0;

CGFloat rotation = _lastRotation * recognizer.rotation;

self.container.transform = CGAffineTransformRotate(self.view.transform, recognizer.rotation);
recognizer.rotation = 0;

if (recognizer.state == UIGestureRecognizerStateEnded)  {
    _lastRotation = rotation;
    return;
}
}

当我添加旋转识别器时,旋转工作但捏/缩放被破坏(从非常小到大的随意跳跃)。我怎样才能解决这个问题,让他们都工作?

4

0 回答 0