我正在尝试为 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 - 使用 UIRotationGestureRecognizer 旋转图像时出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13138826/