minivmac4ios/Mini vMac/KeyboardSceneDelegate.swift

33 lines
1.1 KiB
Swift
Raw Normal View History

2024-02-10 11:15:01 +00:00
//
// KeyboardSceneDelegate.swift
// Mini vMac
//
// Created by Jesús A. Álvarez on 2024-02-10.
// Copyright © 2024 namedfork. All rights reserved.
//
import UIKit
class KeyboardSceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {
fatalError("Expected scene of type UIWindowScene but got an unexpected type")
}
2024-02-10 12:36:20 +00:00
guard let mainViewController = AppDelegate.shared.window.rootViewController as? ViewController else {
2024-02-10 11:15:01 +00:00
fatalError("No main view controller")
}
let size = mainViewController.keyboardViewController.preferredContentSize
windowScene.sizeRestrictions?.minimumSize = size
windowScene.sizeRestrictions?.maximumSize = size
window = UIWindow(windowScene: windowScene)
if let window {
window.rootViewController = mainViewController.keyboardViewController
window.makeKeyAndVisible()
}
}
}