SceneDelegate.swift 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2020, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import UIKit
  17. class SceneDelegate: UIResponder, UIWindowSceneDelegate {
  18. var window: UIWindow?
  19. var navController: UINavigationController?
  20. func scene(
  21. _ scene: UIScene,
  22. willConnectTo session: UISceneSession,
  23. options connectionOptions: UIScene.ConnectionOptions
  24. ) {
  25. // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
  26. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
  27. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
  28. guard let windowScene = (scene as? UIWindowScene) else { return }
  29. self.navController = UINavigationController()
  30. self.navController?.navigationBar.backgroundColor = .blue
  31. self.navController?.navigationBar.prefersLargeTitles = false
  32. let viewController: UIViewController = ViewController()
  33. self.navController?.pushViewController(viewController, animated: false)
  34. self.window = UIWindow(windowScene: windowScene)
  35. self.window!.rootViewController = self.navController
  36. self.window!.backgroundColor = .gray
  37. self.window!.makeKeyAndVisible()
  38. }
  39. func sceneDidDisconnect(_ scene: UIScene) {
  40. // Called as the scene is being released by the system.
  41. // This occurs shortly after the scene enters the background, or when its session is discarded.
  42. // Release any resources associated with this scene that can be re-created the next time the scene connects.
  43. // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
  44. }
  45. func sceneDidBecomeActive(_ scene: UIScene) {
  46. // Called when the scene has moved from an inactive state to an active state.
  47. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
  48. }
  49. func sceneWillResignActive(_ scene: UIScene) {
  50. // Called when the scene will move from an active state to an inactive state.
  51. // This may occur due to temporary interruptions (ex. an incoming phone call).
  52. }
  53. func sceneWillEnterForeground(_ scene: UIScene) {
  54. // Called as the scene transitions from the background to the foreground.
  55. // Use this method to undo the changes made on entering the background.
  56. }
  57. func sceneDidEnterBackground(_ scene: UIScene) {
  58. // Called as the scene transitions from the foreground to the background.
  59. // Use this method to save data, release shared resources, and store enough scene-specific state information
  60. // to restore the scene back to its current state.
  61. }
  62. }