Return viewController 方向。 Swift
Return viewController orientation. Swift
在应用程序中,我只有纵向。
但是有一个视图是横向的。
问题是它们都是通过 NavigationController 连接的。当我从视图返回时,从横向到纵向的方向没有改变。
如何修复 NavigationController 的 dismiss 方法?
AppDelegate.swift
var orientationLock = UIInterfaceOrientationMask.portrait
var myOrientation: UIInterfaceOrientationMask = .portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return myOrientation
}
landscapeView.sift
import UIKit
class SchemeView: UIViewController {
let appDel = UIApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
appDel.myOrientation = .landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
//does not work
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
}
我用下面的方法自己决定一切
override func viewWillDisappear(_ animated: Bool) {
appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
在应用程序中,我只有纵向。 但是有一个视图是横向的。
问题是它们都是通过 NavigationController 连接的。当我从视图返回时,从横向到纵向的方向没有改变。
如何修复 NavigationController 的 dismiss 方法?
AppDelegate.swift
var orientationLock = UIInterfaceOrientationMask.portrait
var myOrientation: UIInterfaceOrientationMask = .portrait
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return myOrientation
}
landscapeView.sift
import UIKit
class SchemeView: UIViewController {
let appDel = UIApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
appDel.myOrientation = .landscape
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
}
//does not work
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
}
我用下面的方法自己决定一切
override func viewWillDisappear(_ animated: Bool) {
appDel.myOrientation = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}