Skip to content

bonyadmitr/OrientationManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OrientationManager

To force only one controller to be at landscape orientation.

Add OrientationManager to project:

```swift
class OrientationManager {

    static let shared = OrientationManager()

    /// you can set any orientation to lock
    var orientationLock = UIInterfaceOrientationMask.portrait

    /// lock orientation and force to rotate device
    func lock(for orientation: UIInterfaceOrientationMask, rotateTo rotateOrientation: UIInterfaceOrientation) {
        orientationLock = orientation
        UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
    }
}
```

Usage:

  1. Add code to AppDelegate

    func application(_ application: UIApplication,
                     supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
            return OrientationManager.shared.orientationLock
    }
  2. Use in controller

    class LandscapeController: UIViewController {
    
        /// orientation for one controller
        override func viewDidLoad() {
            super.viewDidLoad()
            OrientationManager.shared.lock(for: .landscape, rotateTo: .landscapeLeft)
        }
    
        /// set previous state of orientation or any new one
        override func viewWillDisappear(_ animated : Bool) {
            super.viewWillDisappear(animated)
            OrientationManager.shared.lock(for: .portrait, rotateTo: .portrait)
        }
    }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages