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

时间:2010-09-29 14:08:56

标签: iphone

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

由于

1 个答案:

答案 0 :(得分:6)

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

UIPanGestureRecognizer Class Reference

-

<强>更新

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

添加旋转手势识别器:

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

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

- (void)handleGesture:(UIRotationGestureRecognizer *)sender {
    self.myView.transform = CGAffineTransformMakeRotation(sender.rotation);
}
相关问题