将平移手势识别器附加到图像上

awl*_*lcs 1 iphone

有人可以指导我需要做什么吗?我需要将平移手势识别器附加到图像上,这些图像在我们移动时顺时针和逆时针旋转.

谢谢

Yan*_*nol 6

您需要将a附加UIPanGestureRecognizer到图像,并且在调用操作方法时,您可以询问手势的当前平移和速度.然后,您可以根据这些值旋转图像.由于这是一个连续的手势,当平移手势发生变化时,您将收到通知,允许您更新图像的旋转.

UIPanGestureRecognizer类参考

-

更新

我已经重读了你的问题,如果你想通过做一个典型的旋转手势用手指旋转图像,你应该使用UIRotationGestureRecognizer而不是UIPanGestureRecognizer.如果你想做一个向左或向右移动手指的平移手势,你确实必须使用一个UIPanGestureRecognizer.我只是想完成答案.

添加旋转手势识别器:

UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.myView addGestureRecognizer:rotationRecognizer];
[rotationRecognizer release];
Run Code Online (Sandbox Code Playgroud)

处理手势并相应地旋转图像可能看起来像这样(最简单的形式):

- (void)handleGesture:(UIRotationGestureRecognizer *)sender {
    self.myView.transform = CGAffineTransformMakeRotation(sender.rotation);
}
Run Code Online (Sandbox Code Playgroud)