Skip to content

Instantly share code, notes, and snippets.

@justindarc
Created April 30, 2020 22:22
Show Gist options
  • Save justindarc/bcc86d62765d3a1413a9494203ca6f9b to your computer and use it in GitHub Desktop.
Save justindarc/bcc86d62765d3a1413a9494203ca6f9b to your computer and use it in GitHub Desktop.
UIViewController on a second screen
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