I have a UITabViewController with three tabs. On one of the tabs, the user taps a button and a new UIViewController controller pops up in Landscape mode (for the user to sign their name using their finger). After the user is finished, they tap a Finish button and finish() is called which closes the signing UIViewController.
The problem I am facing is the screen that the user returns to that was in Portrait mode is now in Landscape mode even though the screen is set:
override var supportedInterfaceOrientations: UIInterfaceOrientationMask{
return .portrait
}
override var shouldAutorotate: Bool {
return true
}
and there nothing I can do to force rotation back to portrait. I have read posts such as: How to force device rotation in Swift? and as I understand it, there is nothing I can do to rotate the screen back to portrait?
It's really simple. Write the following code and change orientation value in ViewControllers you want to programmatically rotate.
override func viewWillAppear(_ animated: Bool) {
let value = UIInterfaceOrientation.portrait.rawValue //Change orientation according to your scenario
UIDevice.current.setValue(value, forKey: "orientation")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.