Created
January 14, 2019 12:03
-
-
Save FitzAfful/a43878832f33625a1f6a0cc31e899cc5 to your computer and use it in GitHub Desktop.
Lock all other screens and only rotate one controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var orientationLock = UIInterfaceOrientationMask.portrait | |
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") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
AppDelegate.AppUtility.lockOrientation(UIInterfaceOrientationMask.landscapeRight, andRotateTo: UIInterfaceOrientation.landscapeRight) | |
} | |
override func viewWillDisappear(_ animated : Bool) { | |
super.viewWillDisappear(animated) | |
AppDelegate.AppUtility.lockOrientation(UIInterfaceOrientationMask.portrait, andRotateTo: UIInterfaceOrientation.portrait) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment