2012-03-06 66 views
1

我看過一些應用程序,它們可以同時縮放和旋轉圖像。它不需要釋放手指觸摸。如何順利地縮放和旋轉?

我下面的代碼需要到: 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]; 
    } 

回答

0

這裏是您需要的代碼...將此方法添加到您的文件.m

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
    return YES; 
}