如何在 swift 中更改图像方向

How to change the image orientation in swift

我有一个图像视图,图像视图将从相机获取图像,但问题是当我想显示图像视图时图像的方向是横向的。 这是我的代码

class ResultViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {
var userData2 = userData()

    var base64String1: String!
    var decodedData1: Data!
    var decodedImage1: UIImage!
    @IBOutlet weak var imageResult: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        base64String1 = userData2.fotoIDString!
        decodedData1 = Data(base64Encoded: base64String1, options: [])!
        decodedImage1 = UIImage(data: decodedData1)!
        imageResult.image = decodedImage1



       }

您需要转换图像视图的方向

imageResult.transform = CGAffineTransformMakeRotation(M_PI_2);

以下代码将图像旋转 90 度 Swift 3

imageResult.transform = CGAffineTransform(rotationAngle: .pi/2)