问题
Some quick issues, i have 5 VC
on stack. when i am in my second VC, then if i rotate to landscape and when i move to 1st
VC my layout is totally collapsed.
in my second VC i added viewWillTransition
and i am invalidateLayout
of my table view. And if i add tableview.reloaddata()
in my first screen viewWillAppear .Then it's fine.
But consider if i have 5 VC on stack i can not write code in all VC. Is there any better way to handle it.
回答1:
In your app delegate add this....
var orientationLock = UIInterfaceOrientationMask.all
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
struct AppUtility {
static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.orientationLock = orientation
}
}
static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
self.lockOrientation(orientation)
UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
}
}
Used this from any view controller like this...
AppDelegate.AppUtility.lockOrientation(UIInterfaceOrientationMask.portrait, andRotateTo: UIInterfaceOrientation.portrait)
来源:https://stackoverflow.com/questions/57770781/handle-orientation-with-multiple-stack-of-viewcontrollers