0

I'd like to fix my Camera View in landscape Mode. And also show an alert when user rotate view to portrait. is there any solution available ?

Lijith Vipin
  • 1,870
  • 21
  • 29

1 Answers1

0

Put this in your view controller:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.current.orientation.isLandscape {
        print("will turn to landscape")
    } else {
        print("will turn to portrait")
        //print an alert box here
        UIDevice.current.setValue(UIInterfaceOrientation.landscapeLe‌​ft.rawValue, forKey: "orientation")
    }
}

Source: How to detect orientation change?

Or put this to the view that needs to be in landscape:

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.landscape
}

But this one cannot post an alert.

Community
  • 1
  • 1
Papershine
  • 4,995
  • 2
  • 24
  • 48