我看過一些應用程序,它們可以同時縮放和旋轉圖像。它不需要釋放手指觸摸。如何順利地縮放和旋轉?
我下面的代碼需要到: 1.觸摸縮放 2.釋放 3.觸摸旋轉
如何調整,並在同一時間轉動?
在我的主要代碼:
UIPanGestureRecognizer *imagePanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)];
[imagePanGesture setMinimumNumberOfTouches:1];
[imagePanGesture setMaximumNumberOfTouches:1];
[tempImageView addGestureRecognizer:imagePanGesture];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleImage:)];
[tempImageView addGestureRecognizer:pinchGesture];
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotateImage:)];
[tempImageView addGestureRecognizer:rotationGesture];
在個別縮放和旋轉
- (void)scaleImage:(UIPinchGestureRecognizer *)recognizer
{
if([recognizer state] == UIGestureRecognizerStateEnded)
{
previousScale = 1.0;
return;
}
CGFloat newScale = 1.0 - (previousScale - [recognizer scale]);
CGAffineTransform currentTransformation = [recognizer view].transform;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransformation, newScale, newScale);
[[recognizer view] setTransform:newTransform];
previousScale = [recognizer scale];
}
- (void)rotateImage:(UIRotationGestureRecognizer *)recognizer
{
if([recognizer state] == UIGestureRecognizerStateEnded) {
previousRotation = 0.0;
return;
}
CGFloat newRotation = 0.0 - (previousRotation - [recognizer rotation]);
CGAffineTransform currentTransformation = [recognizer view].transform;
CGAffineTransform newTransform = CGAffineTransformRotate(currentTransformation, newRotation);
[[recognizer view] setTransform:newTransform];
previousRotation = [recognizer rotation];
}
非常感謝!這是我正在尋找的笏。 – RockBaby 2012-03-06 03:26:37