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 ?
Asked
Active
Viewed 2,705 times
1 Answers
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.landscapeLeft.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
-
@LijithVipin - portait is locked means – Anbu.Karthik Mar 04 '17 at 12:07
-
@LijithVipin I don't get what you trying to say, can you elaborate? – Papershine Mar 04 '17 at 12:12