我有一个imageView,我已经添加了UIPinchGestureRecognizer和UIRotationGestureRecognizer。如何在保持原有旋转变换的同时进行缩放?
在捏手势,我转换和缩放视图和旋转手势我对它应用旋转变换。
问题是当我旋转imageView,然后开始缩放。缩放总是从正常状态开始。
所以我想要的是当我旋转它说顺时针30度,然后放大它。它应该在顺时针方向保持30度的同时进行缩放。
下面是代码:
- (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) ;
}
你能分享你用旋转和缩放图像视图的代码? – sch 2012-02-24 15:13:46
@sch:请现在检查。我已经添加了代码。 – 2012-02-24 15:32:49
查看本教程:[iOS 5中的UIGestureRecognizer教程:捏,平底锅等!](http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more )如果您已经知道如何处理手势识别器,请跳转到* Simultaneous Gesture Recognizers * – Frade 2012-02-24 15:32:05