有没有办法始终从肖像呈现视图控制器?例如,如果我处于横向模式,左侧是主页按钮,则视图控制器从左侧显示。它总是从相对于视图的底部呈现
//When button is pressed
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "viewContoller") as! CustomViewController
self.present(viewController, animated: true, completion: nil)
//App delegate
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return .all
}
答案 0 :(得分:0)
override func viewDidLoad() {
super.viewDidLoad()
UIView.performWithoutAnimation({
let value = UIInterfaceOrientation.portrait.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
UIViewController.attemptRotationToDeviceOrientation()
})
}