我有一个imageView,我已经添加了UIPinchGestureRecognizer和UIRotationGestureRecognizer .
在捏手势,我变换和缩放视图和旋转手势我应用旋转变换 .
问题是我旋转imageView然后开始缩放 . 缩放总是从正常状态开始 .
所以我想要的是当我将它旋转到顺时针旋转30度然后缩放它 . 它应该在顺时针方向保持30度的同时进行变焦 .
Here is the code:
- (void)viewDidLoad{
[super viewDidLoad];
//setting up the image view
mTotalRotation = 0.0;
self.imageView.image = self.photo;
self.imageView.userInteractionEnabled = YES;
UIRotationGestureRecognizer *twoFingersRotate =
[[[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(twoFingersRotate:)] autorelease];
[self.imageView addGestureRecognizer:twoFingersRotate];
UIPinchGestureRecognizer *pinchGesture = [[[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchZoom:)] autorelease];
[self.imageView addGestureRecognizer:pinchGesture];
// Do any additional setup after loading the view from its nib.
}
// Rotation gesture handler
- (void)twoFingersRotate:(UIRotationGestureRecognizer *)recognizer
{
if ([recognizer state] == UIGestureRecognizerStateEnded) {
mTotalRotation += recognizer.rotation;
return;
}
self.imageView.transform = CGAffineTransformMakeRotation(mTotalRotation + recognizer.rotation);
}
// Pinch Gesture
-(void)pinchZoom:(UIPinchGestureRecognizer*)recognizer{
self.imageView.transform = CGAffineTransformMakeScale(recognizer.scale, recognizer.scale) ;
}
2 回答
换行:
有:
和行:
有:
编辑
要限制比例,您可以执行以下操作:
也许您可以将缩放和旋转视图作为缩放视图的子视图?