Created
April 30, 2020 22:22
-
-
Save justindarc/bcc86d62765d3a1413a9494203ca6f9b to your computer and use it in GitHub Desktop.
UIViewController on a second screen
This file contains hidden or 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
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
let secondStoryboard = UIStoryboard(name: "SecondScreen", bundle: nil) | |
let secondScreenVC = secondStoryboard.instantiateInitialViewController() as! SecondScreenViewController | |
secondScreenVC.loadViewIfNeeded() | |
let secondWindow = UIWindow() | |
secondWindow.addSubview(secondScreenVC.view) | |
secondWindow.rootViewController = secondScreenVC | |
NotificationCenter.default.addObserver(forName: UIScreen.didConnectNotification, object: nil, queue: .main) { (notification) in | |
guard let secondScreen = notification.object as? UIScreen else { | |
return | |
} | |
secondWindow.screen = secondScreen | |
secondWindow.makeKeyAndVisible() | |
} | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment