使用UIRotationGestureRecognizer旋转图像时出现问题?

时间:2012-10-30 12:19:03

标签: iphone ios5 uigesturerecognizer cgaffinetransform image-rotation

我正在尝试为UIRotationGestureRecognizer实施UIImageView

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)

可能是什么原因?如何修理中心?如何使用UIImageView?{/ p>使我的图像在UIRotationGestureRecognizer的中心旋转

1 个答案:

答案 0 :(得分:4)

尝试使用

recognizer.rotation = 0;

这是一个教程。希望它有所帮助

Link