샘성의 iOS 개발 일지

UIWindow 객체의 역할은 무엇인가? 본문

iOS/면접

UIWindow 객체의 역할은 무엇인가?

SamusesApple 2023. 6. 22. 10:35
728x90

UIWindow

  : UIView의 하위 클래스로, 앱의 UI를 담는 컨테이너이자 View에 이벤트를 전달하는 객체

  • UIWindow 자체만으로는 눈에 보이는 내용을 띄울 수는 없음 (View를 담아서 컨텐츠를 띄움)
  • 모든 앱은 1개의 UIWindow를 갖고 있다. (iOS 13.0 이후로는 아이패드에선 1개의 앱이 여러개의 Window를 가질 수 있음)
  • UIWindow는 액자, 그 액자에 들어가는 사진은 UIView
* 13.0 이후 SceneDelegate의 scene will connectTo

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        let contentView = ContentView()
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = MainViewController() // VC를 window의 rootVC로 지정
            self.window = window
            window.makeKeyAndVisible()
        }
    }
728x90