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

标签 iphone ios5 uigesturerecognizer cgaffinetransform image-rotation

我正在尝试为 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 的中心旋转?

最佳答案

尝试使用

recognizer.rotation = 0;

这是一个教程。希望对您有帮助

Link

关于iphone - 使用 UIRotationGestureRecognizer 旋转图像时出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138826/

相关文章:

iphone - 将数据传递给 subview

ios - 获取 UIBezierPath IOS 的面积和周长

iphone - subview 中的触摸检测

iphone - 带删除线的字体

iphone - 延迟位置更新 iOS 6

ios - 使用另一个动态 UIImage mask UIImage

ios - 2 个同步的 UILongPressGestureRecognizer

iphone - 三层Pan Gesture Recogniser的困惑

iphone - 后台任务是这个问题的解决方案吗?

iphone - 自 iOS 8.3 以来,自定义 UITableView 原型(prototype)单元格约束有什么变化吗?