I tried the next:
UIDevice.currentDevice().setValue(UIInterfaceOrientation.Portrait.rawValue, forKey: \"orientation\")
on
swift 5
import UIKit extension UIViewController { class func setUIInterfaceOrientation(_ value: UIInterfaceOrientation) { UIDevice.current.setValue(value.rawValue, forKey: "orientation") } }