UIImage rotate according to device orientation

Hey, I'm working on a camera app. I've got a few outlets for various buttons and attaching tap gestures to perform the actions.

I've enabled only Portrait orientation in Deployment Info & disabled the remaining.

When the device rotates, I want to rotate the UIImage according to the device orientation. How to do that?

Then you need to detect device has rotated and rotate your image programmatically. Do it in:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { // 19.5.2018
    
    super.viewWillTransition(to: size, with: coordinator)
   // Rotate the UIImage itself here
}

But what will happen to the buttons ? They will not rotate. So the 3 goals may be conflicting

  • I've got a few outlets for various buttons
  • enabling only Portrait orientation
  • rotate the UIImage according to the device orientation
UIImage rotate according to device orientation
 
 
Q