My app is landscape mode except for one single VC. TopVC is landscape but when loading MyVC it should be rotate according to device orientation. Loading MyVC working as expect but returning to TopVC is not showing correctly if the mode portrait(landscape mode is fine).
here is the code I tried
in AppDelegate.swift
var orientationLock = UIInterfaceOrientationMask.landscape
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return self.orientationLock
}
func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
self.orientationLock = orientation
}
in MyVC.swift
override func viewWillAppear(_ animated: Bool) {
// change orientation
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.lockOrientation(.allButUpsideDown)
}
}
override func viewWillDisappear(_ animated: Bool) {
if let delegate = UIApplication.shared.delegate as? AppDelegate {
delegate.lockOrientation(.landscapeLeft)
}
}
Can someone help me to resolve this? Problem is return back to TopVC showing in portrait mode if it returning portrait mode from MyVC.