2013-02-05 127 views
-1

我已經爲UIImageView實現了旋轉手勢。UIImageView的旋轉手勢

這裏是我的實現代碼:

- (IBAction)rotaehandler:(UIRotationGestureRecognizer *)sender 
{ 
    sender.view.transform = CGAffineTransformRotate(sender.view.transform, sender.rotation); 
} 

我連接到UIRotationGestureRecognizerUIImageView。 它的工作原理,但是,我怎樣才能旋轉圖像形式的中心。

+2

輸入的概念[ 「分裂」](http://en.wikipedia.org/wiki/Division_(數學)) 。 – 2013-02-05 07:32:43

+2

@ShaaberAli如果您閱讀我鏈接到的維基百科文章,您會看到這個基本的數學運算解釋得非常好。 – 2013-02-05 07:35:53

+0

'CGAffineTransformRotate(sender.view.transform,sender.rotation/SOME_CONSTANT)' – 2013-02-05 07:53:12

回答

1
CGFloat initialRotation = atan2f(sender.view.transform.b-somefloat, sender.view.transform.a-somefloat); 

CGFloat newRotation = initialRotation + sender.rotation; 

sender.view.transform = CGAffineTransformMakeRotation(newRotation); 

嘗試上述代碼

-1

嘗試這種情況:

- (IBAction)rotaehandler:(UIRotationGestureRecognizer *)sender 
    { 


     if ([sender state] == UIGestureRecognizerStateBegan || [sender state] == 
       UIGestureRecognizerStateChanged) 
     { 
      [sender view].transform = CGAffineTransformRotate([[sender view] transform], 
                   [sender rotation]); 

      NSLog(@"Rotate : %f",[gestureRecognizer rotation]); 
      [sender setRotation:0]; 
     } 
    } 
+0

可以粘貼你的代碼你如何在Image View上添加你的手勢? –

+0

請檢查http://stackoverflow.com/questions/11104042/how-to-get-a-rotated-zoomed-and-panned-image-from-an-uiimageview-at-its-full-re this將幫助你 –