UIScrollView 与 UIRotationGestureRecognizer 的缩放问题
我有一个显示图像视图的滚动视图。我正在尝试处理图像视图上的 UIRotationGestureRecognizer。我获取旋转事件并对其应用所需的变换。图像在滚动视图中正确旋转。然后,当我在滚动视图中执行任何操作(如缩放或平移)时,图像旋转和位置会进行抛掷
_mainView 是 UIScrollView 的子视图,也用于缩放,
UIRotationGestureRecognizer *rotationGesture=[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationGesture:)];
[_mainView addGestureRecognizer:rotationGesture];
[rotationGesture release];
-(void) rotationGesture:(UIRotationGestureRecognizer *) sender {
if(sender.state == UIGestureRecognizerStateBegan ||
sender.state == UIGestureRecognizerStateChanged)
{
sender.view.transform = CGAffineTransformRotate(sender.view.transform,
sender.rotation);
_currRotation = _currRotation + sender.rotation;
[sender setRotation:0];
}
}
我想了解处理旋转的正确方法是什么- 在滚动视图中,即使在滚动视图中发生缩放事件后,它也会保持旋转。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 方法,并返回您想要同时识别的所有手势。如果您仍然遇到问题,请查看 UIImageView 手势(缩放、旋转)问题的答案< /a>.
祝你好运!
编辑:您的评论让我猜测问题是您一次只能进行一种变换,并且滚动视图应用缩放变换,取代旋转变换。您可以删除本机缩放识别器(请参阅此问题< /a>),或者在滚动视图中嵌套另一个 UIView,然后对其应用旋转变换。我喜欢选项二,看起来更容易。如果您选择选项一,请使用 CGAffineTransformConcat 独立应用缩放和旋转变换。
Implement the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method in your UIGestureRecognizerDelegate, and return all gestures you want to recognize simultaneously. If you still have trouble with it, check out the answers to UIImageView Gestures (Zoom, Rotate) Question.
Good luck!
EDIT: Your comment has me guessing that the issue is that you can only have one transform on at a time, and the scroll view applies a scale transform, replacing the rotation one. You could remove the native zoom recognizer (see this question), or nest another UIView in the scroll view, and apply the rotation transform to that. I like option two, it seems easier. If you go with option one, use CGAffineTransformConcat to apply both the zoom and rotate transformations independently.