1

如何在iPhone編程中旋轉圖像?如何旋轉iPhone上的圖像?

+0

Dupe? http://stackoverflow.com/questions/917713/uiimage-rotation-custom-degrees – crashmstr 2009-06-05 12:53:16

+0

可能是一個騙局,但取決於OP實際上想做什麼。 Raju,目標是什麼?你的意思是「獲取旋轉的UIImage的副本嗎?」或者也許「顯示旋轉的圖像?」或者,也許「使圖像旋轉動畫?」這是一個非常含糊的問題。 – 2009-06-05 14:17:29

+0

這也可能類似於他所問:http://stackoverflow.com/questions/839296/how-can-i-rotate-a-uiimageview-with-respect-to-any-point-other-than-its - 中心 – 2009-06-05 16:24:38

回答

0

您可以使用CCGAffineTransform旋轉視圖。您可以通過指定要旋轉的弧度度數來創建旋轉矩陣,然後將旋轉矩陣設置爲視圖的.transform屬性。

1
image.transform = CGAffineTransformMakeRotation(3.142); 

旋轉180度。

0
//If someone needs in swift 3 



    func rotateImageClockWise(theImage: UIImage,imageView:UIImageView) -> UIImage { 

     var orient: UIImageOrientation! 
     let imgOrientation = theImage.imageOrientation 


     UIView.transition(with: imageView, duration: 0.2, options: .transitionCrossDissolve, animations: {() -> Void in 

      switch imgOrientation { 

      case .left: 
       orient = .up 

      case .right: 
       orient = .down 

      case .up: 
       orient = .right 

      case .down: 
       orient = .left 

      case .upMirrored: 
       orient = .rightMirrored 

      case .downMirrored: 
       orient = .leftMirrored 

      case .leftMirrored: 
       orient = .upMirrored 

      case .rightMirrored: 
       orient = .downMirrored 
      } 


     }, completion: { _ in }) 

     let rotatedImage = UIImage(cgImage: theImage.cgImage!, scale: 1.0, orientation: orient) 
     return rotatedImage 
    } 
//Just call the method like this : 

rotateImageClockWise(theImage: UIImage,imageView:UIImageView)