【问题标题】:Issue while using UIRotationGestureRecognizer to rotate Image?使用 UI 旋转手势识别器旋转图像时出现问题?
【发布时间】:2012-10-30 12:19:02
【问题描述】:

我正在尝试为UIImageView 实现UIRotationGestureRecognizer

UIRotationGestureRecognizer *rotateGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];

[self.view addGestureRecognizer:rotateGesture];

在选择器方法中,我没有这个

-(void)rotate:(UIRotationGestureRecognizer *)gesture
{

    if ([gesture state] == UIGestureRecognizerStateBegan || [gesture state] == UIGestureRecognizerStateChanged) {
        selectedImage.transform=CGAffineTransformRotate(selectedImage.transform, gesture.rotation);

        [gesture setRotation:0];
    }

}

使用上面的代码,图像正在旋转。但是,问题是,图像中心正在改变。这样,图像旋转看起来有点尴尬。

图片的初始中心是(277,653) 旋转时,价值会增加直到(365,659),然后又回到(277,653)

可能是什么原因?怎么解决中心问题?如何使用UIRotationGestureRecognizer 使我的图像在UIImageView 的中心旋转?

【问题讨论】:

    标签: iphone ios5 uigesturerecognizer cgaffinetransform image-rotation


    【解决方案1】:

    尝试使用

    recognizer.rotation = 0;
    

    这里有一个教程。希望对你有帮助

    Link

    【讨论】:

    • 我做的和他做的一模一样。我已经运行了示例代码。它工作正常。但是,如果我写,那么我又面临着这个问题。我正在使用iOS6。我使用的 SDK 也是最新的。最新的 SDK 有问题吗?您可以使用最新的 SDK 尝试一次吗?我遇到了同样的问题
    • 发现问题。这是因为 iOS 6 中的 AutoLayout 功能。我已取消选择它。现在,它工作正常。无论如何,谢谢。
    猜你喜欢
    • 2012-08-15
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 2018-02-01
    • 2011-03-27
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多