[英]How do I rotate an image on the iPhone?
如何在iPhone編程中旋轉圖像?
可以在以下位置找到Allen Brunson出色的旋轉和圖像UIImage類別: http : //www.platinumball.net/blog/2010/01/31/iphone-uiimage-rotation-and-scaling/
image.transform = CGAffineTransformMakeRotation(3.142);
將其旋轉180度。
//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)
您可以使用CCGAffineTransform旋轉視圖。 您可以通過指定要旋轉的弧度數來創建旋轉矩陣,然后將旋轉矩陣設置為視圖的.transform屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.