【问题标题】:UIScrollView zoom issue with UIRotationGestureRecognizerUIRotationGestureRecognizer 的 UIScrollView 缩放问题
【发布时间】:2011-12-31 05:59:57
【问题描述】:

我有一个显示图像视图的滚动视图。我正在尝试处理图像视图上的 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];
    }
}

我想了解在滚动视图中处理旋转的正确方法是什么,即使在滚动视图中发生缩放事件之后它也会保持这种旋转。

【问题讨论】:

    标签: iphone ios rotation scrollview


    【解决方案1】:

    在您的 UIGestureRecognizerDelegate 中实现 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 方法,并返回您想要同时识别的所有手势。如果您仍然遇到问题,请查看UIImageView Gestures (Zoom, Rotate) Question 的答案。

    祝你好运!

    编辑:您的评论让我猜测问题是您一次只能进行一个变换,并且滚动视图应用缩放变换,替换旋转变换。您可以删除本机缩放识别器(请参阅this question),或在滚动视图中嵌套另一个 UIView,然后对其应用旋转变换。我喜欢选项二,它似乎更容易。如果您选择选项一,请使用 CGAffineTransformConcat 独立应用缩放和旋转变换。

    【讨论】:

    • 谢谢,我已经添加了。问题不在于手势识别器。主要问题是一旦发生旋转并且如果我滚动或缩放旋转会折腾并且图像在滚动视图中不再正确对齐
    猜你喜欢
    • 2012-12-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2012-04-06
    • 2014-07-09
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    相关资源
    最近更新 更多