UIWindow

Wongbing·2022년 11월 24일
0

Apple Docs

목록 보기
11/11
tags: 문서스터디

The backdrop for your app’s user interface and the object that dispatches events to your views.

앱의 사용자 인터페이스의 배경막이고, 뷰에 이벤트를 보내주는 객체입니다.

🔘 Decalaration

@MainActor class UIWindow: UIView

🔘 Overview

Windows work with your view controllers to handle events and to perform many other tasks that are fundamental to your app’s operation. UIKit handles most window-related interactions, working with other objects as needed to implement many app behaviors.

Window 는 이벤트 처리와 앱 작동에 기본이 되는 많은 이벤트를 수행하기 위해 뷰 컨트롤러와 상호작용 합니다. UIKit은 대부분 Window와 관련된 상호작용을 하며, 많은 앱 동작을 구현하기 위해 필요에 따라 다른 객체들과 협력합니다.

You use windows only when you need to do the following:

  • Provide a main window to display your app's content
  • Create additional windows (as needed) to display additional content

다음의 경우 window를 사용하게 됩니다 :

  • 앱 컨텐트를 보여주기 위한 main window를 제공할 때
  • 추가적인 컨텐트를 보여주기 위한 추가적인 window를 생성할 때

Normally, Xcode provides your app's main window. New iOS projects use storyboards to define the app's views. Storyboards require the presence of a window property on the app delegate object, which the Xcode templates automatically provide. If your app doesn't use storyboards, you must create this window yourself.

보통 Xcode는 당신 앱의 main window를 제공합니다. 새로운 iOS 프로젝트는 앱의 뷰를 정의하기 위해 storyboard를 사용합니다. Storyboard는 Xcode 템플릿이 자동으로 제공해주는 app delegate 객체에 window 프로퍼티를 요구합니다.
만약 스토리보드를 사용하지 않는다면, 스스로 window를 생성해야만 합니다.

Most apps need only one window, which displays the app's content on the device's main screen. Although you can create additional windows on the device's main screen, extra windows are commonly used to display content on an external screen, as described in Presenting content on a connected display.

대부분의 앱들은 하나의 window만 필요합니다. 이는 기기의 메인스크린에 앱 컨텐트를 보여줍니다. 비록 기기의 메인스크린에 추가적인 window를 생성할 수 있지만, 여분의 windows는 공통적으로 외장 스크린에서 컨텐트를 보여줄 때 사용되곤 합니다.

You also use UIWindow objects for a handful of other tasks:

  • Setting the z-axis level of your window, which affects the visibility of the window relative to other windows.
  • Showing windows and making them the target of keyboard events.
  • Converting coordinate values to and from the window's coordinate system.
  • Changing the root view controller of a window
  • Changing the screen on which the window is displayed.

또한 UIWindow 객체로 소수의 다른작업도 합니다:

  • window의 z-좌표를 설정하여 다른 window와 연관된 window의 가시성에 영향을 줍니다.
  • window를 보여주는것과 키보드 이벤트의 타겟으로 만드는 것
  • window의 좌표시스템에서 좌표값을 변환하는 것
  • window의 rootViewController를 바꾸는 것
  • window가 띄워진 스크린을 바꾸는 것

Windows don’t have any visual appearance of their own. Instead, a window hosts one or more views, which are managed by the window’s root view controller. You configure the root view controller in your storyboards, adding whatever views are appropriate for your interface.
You should rarely need to subclass UIWindow. The kinds of behaviors you might implement in a window can usually be implemented in a higher-level view controller more easily. One of the few times you might want to subclass is to override the becomeKey() or resignKey() methods to implement custom behaviors when a window’s key status changes. For information about how to display a window on a specific screen, see UIScreen.

Window 는 스스로 시각적인 형태를 가지지 않습니다. 대신 window의 root view controller에 의해 관리되는 하나이상의 뷰를 주최합니다. 스토리보드에서 루트 뷰 컨트롤러를 구성하여 인터페이스에 적합한 뷰를 추가합니다. UIWindow를 상속할 일은 거의 없을겁니다. window에서 구현할지도 모르는 행동종류는 보통 상위레벨의 view controller에서 더 쉽게 구현할 수 있습니다.(uiwindow상속해서 처리해야될 것 같은 일들은 상위 VC에서 더 쉽게 처리할 수 있다) 당신이 상속하길 원하는 몇몇의 경우중 하나는 window의 key status가 변경될 때 커스텀 동작을 구현하기 위해 becomeKey() 와 resignKey() 를 재정의 할 경우입니다.

🔘 Understand keyboard interactions

Whereas touch events are delivered to the window where they occurred, events that don’t have a relevant coordinate value are delivered to the key window. Only one window at a time can be the key window, and you can use a window’s isKeyWindow property to determine its status. Most of the time, your app’s main window is the key window, but UIKit may designate a different window as needed.

터치 이벤트는 발생한 window 로 전달되는 반면, 관련 좌표 값이 없는 이벤트는 key window 로 전달됩니다. 한번에 오직 하나의 windowkey window 가 될 수 있고, window 의 상태를 결정하기 위해 windowisKeyWindow 프로퍼티를 이용할 수 있습니다.

If you need to know which window is key, observe the didBecomeKeyNotification and didResignKeyNotification notifications. The system sends those notifications in response to key window changes in your app. To force a window become key, or to force a window to resign the key status, call the appropriate methods of this class.

만약 어떤 windowkey 인지 알아야 한다면, didBecomeKeyNotificationdidResignKeyNotification notification을 관찰하십시오. 시스템이 앱에서 key window 가 바뀌는 것에 대한 응답으로 이 notification들을 보냅니다. window를 강제로 key로 바꾸거나 resign 하려면 이 클래스에 적절한 메서드를 호출하십시오.

🛠 Trouble Shooting

⚙️ window , scene, screen 개념 중, 어느 것이 상위 개념인가?

  • 먼저 UIScreen 은 물리적인 디바이스의 화면을 지칭한다. 가장 상위 개념이다
  • UIWindow 의 이니셜라이저로 init(windowScene: UIWindowScene) 이 있다. UIWindowScene 은 UIScene을 상속받고 있고, var keyWindow: UIWindow 를 프로퍼티로 가지고 있다.
  • UIWindowScene 하위에 window가 있고, window는 보통 앱마다 하나만 필요하고, 아이패드의 경우 Apple Docs - Supporting Multiple Windows on iPad 여러개의 윈도우를 가진다고 한다.

⚙️ 정리

  • iOS 앱은 모든 View들의 컨테이너 역할을 하는 UIWindow인스턴스를 하나 가지는데, (app delegate에 정의되어 있다.) UIWindow는 UIView의 하위클래스 이므로 Window는 그 자체가 View라고 할 수 있다.
  • 뷰를 포함할 수 있는 비어있는 컨테이너이다.

🔗 Reference

profile
IOS 앱개발 공부

0개의 댓글