我有一個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