How to rotate an image 90 degrees on iOS?

后端 未结 14 1853
野的像风
野的像风 2020-11-29 00:55

What I want to do is take a snapshot from my camera , send it to a server and then the server sends me back the image on a viewController. If the image is in portrait mode t

14条回答
  •  醉梦人生
    2020-11-29 01:31

    Swift 4+.

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

    Note: angle is in radian

    .pi = 180 degree

    .pi/2 = 90 degree

    If you want to add with animation

      @IBAction func applyTransForm(sender: UIButton) {
            sender.isSelected = !sender.isSelected
            UIView.animate(withDuration: 1, animations: {
            if sender.isSelected {
                self.arrowImageView.transform = CGAffineTransform(rotationAngle: .pi)
            } else {
                self.arrowImageView.transform = CGAffineTransform(rotationAngle: 0)
    
            }
            })
        }
    

    Output:

提交回复
热议问题