Swift 100 Days: Project 24 - How To Rotate Only One ViewController to Landscape Orientation?
Sunny, Lee
1549

here’s another solution, less verbose:

Put this into your AppDelegate.swift:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {

if let rootViewController = window?.rootViewController?.presentedViewController {

// Using class kind

// if rootViewController.isKind(of: YourViewControllerClass.self) {

// return .allButUpsideDown

// }

// Or Using a selector -> Put this in the ViewController you want to rotate: @objc func canRotate() -> Void {}

if (rootViewController.responds(to: Selector((“canRotate”)))) {

return .allButUpsideDown;

}

}

// Only allow portrait (standard behaviour)

return .portrait;

}

I prefer the kinfOf method, but it’s really up to you