Example project to show how to control the rotation of your application's view controllers.
Based on Swift 100 Days: Project 24 - How To Rotate Only One ViewController to Landscape Orientation?. This version is using protocols and extensions and
- Rotation/UIViewController+Extensions.swift
- Rotation/AppDelegate.swift
- Rotation/RotationEnabled.swift
- Rotation/SecondViewController.swift
- Create the UIViewController extension to determine the top most presented view controller.
- Create the RotationEnabled protocol to mark each ViewController that supports rotation.
- Implement in the AppDelegate the method
func application(UIApplication, supportedInterfaceOrientationsFor: UIWindow?) -> UIInterfaceOrientationMask
to report the supported orientations. - Mark each view controller that should support rotation with the RotationEnabled protocol
and implement the
canRotate
requirement and add code to viewWillDisappear to reset the rotation to portrait when the view will disappear from the screen. if (self.isMovingFromParent) { UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation") }