Slide 1

Slide 1 text

ৄղUIWindow iOSDC Japan 2024 2024/08/23(ۚ) 15:40-16:00 Track A 1 pixiv Inc. atsuyan

Slide 2

Slide 2 text

2 atsuyan / ͋ͭ΍ (𝕏: @n_atmark) ϐΫγϒגࣜձࣾ ৽نࣄۀ෦ iOSΤϯδχΞ 2024೥2݄த్ೖࣾ iPad޲͚ϖΠϯτπʔϧPastelaͷ։ൃΛ୲౰ ϘϧμϦϯά͕झຯͰ͢!

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

ΞδΣϯμ • UIWindow͸Ͳ͏͍͏Ϋϥεͳͷ͔ • UIWindowͷදࣔํ๏ͱಛੑʹ͍ͭͯ • SwiftUIͰͷUIWindowऔಘʹ͍ͭͯ • ·ͱΊ 4

Slide 5

Slide 5 text

UIWindow͸Ͳ͏͍͏Ϋϥεͳͷ͔ 5

Slide 6

Slide 6 text

6 UIWindow | Apple Developer Documentation - https://developer.apple.com/documentation/uikit/uiwindow

Slide 7

Slide 7 text

UIWindowͷ໾ׂ 7 ΞϓϦͷίϯςϯπΛදࣔ͢ΔͨΊͷ΢Οϯυ΢ͷఏڙ

Slide 8

Slide 8 text

UIWindowͷ໾ׂ • දࣔ͢ΔrootViewControllerͷ؅ཧ • ࠲ඪ஋ͷม׵ • ΩʔϘʔυΠϕϯτͷλʔήοτ؅ཧ • ΢Οϯυ΢ͷॏͳΓ(Z࣠Ϩϕϧ)ͷ؅ཧ 8 ΞϓϦͷίϯςϯπΛදࣔ͢ΔͨΊͷ΢Οϯυ΢ͷఏڙ

Slide 9

Slide 9 text

UIWindowͷ໾ׂ • දࣔ͢ΔrootViewControllerͷ؅ཧ 9 var rootViewController: UIViewController? { get set }

Slide 10

Slide 10 text

UIWindowͷ໾ׂ • ࠲ඪ஋ͷม׵ 10 func convert(_ point: CGPoint, to window: UIWindow?) -> CGPoint func convert(_ point: CGPoint, from window: UIWindow?) -> CGPoint func convert(_ rect: CGRect, to window: UIWindow?) -> CGRect func convert(_ rect: CGRect, from window: UIWindow?) -> CGRect

Slide 11

Slide 11 text

UIWindowͷ໾ׂ • ΩʔϘʔυΠϕϯτͷλʔήοτ؅ཧ 11 var isKeyWindow: Bool { get } var canBecomeKey: Bool { get } func makeKeyAndVisible() func makeKey() func becomeKey() func resignKey()

Slide 12

Slide 12 text

UIWindowͷ໾ׂ • ΢Οϯυ΢ͷॏͳΓ(Z࣠Ϩϕϧ)ͷ؅ཧ 12 var windowLevel: UIWindow.Level { get set }

Slide 13

Slide 13 text

UIWindowͷؔ࿈Ϋϥε • ը໘αΠζΛऔಘ͍ͨ͠৔߹ʹݕ౼͞ΕΔΫϥε • UIScreen • UIWindowScene • UIWindow • UIView 13

Slide 14

Slide 14 text

14 Introducing Multiple Windows on iPad | WWDC19 - https://developer.apple.com/videos/play/wwdc2019/212/ ~ iOS 13.0

Slide 15

Slide 15 text

15 Introducing Multiple Windows on iPad | WWDC19 - https://developer.apple.com/videos/play/wwdc2019/212/ iOS 13.0+

Slide 16

Slide 16 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 17

Slide 17 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 18

Slide 18 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 19

Slide 19 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 20

Slide 20 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 21

Slide 21 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 22

Slide 22 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 23

Slide 23 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 24

Slide 24 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 25

Slide 25 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 26

Slide 26 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 27

Slide 27 text

"Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 28

Slide 28 text

"Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 29

Slide 29 text

UIWindowͷؔ࿈Ϋϥε • UIScreen … ෺ཧతͳσόΠεͷը໘αΠζ • UIWindowScene … γʔϯͷը໘αΠζ • UIWindow … ΢Οϯυ΢ͷը໘αΠζ • UIView … Viewͷը໘αΠζ 29

Slide 30

Slide 30 text

αΠζΛͲ͏औಘ͢Δ͔ • αΠζऔಘͷ஫ҙ 30 UIApplication.shared.keyWindow UIApplication.shared.windows UIScreen.screens UIScreen.main

Slide 31

Slide 31 text

αΠζΛͲ͏औಘ͢Δ͔ • αΠζऔಘͷ஫ҙ 31 @available(iOS, introduced: 2.0, deprecated: 13.0, message:ŋŋŋ) UIApplication.shared.keyWindow @available(iOS, introduced: 2.0, deprecated: 15.0, message:ŋŋŋ) UIApplication.shared.windows @available(iOS, introduced: 3.2, deprecated: 16.0, message:ŋŋŋ) UIScreen.screens // soft-deprecated @available(iOS, introduced: 2.0, deprecated: 100000, message:ŋŋŋ) UIScreen.main

Slide 32

Slide 32 text

UIScreen.screens ͲͷΠϯελϯε ͕Ͳͬͪͩ…? iPadଆͷαΠζ͸ҰԠUIScreen.main ͰऔΕ͸͢Δ͕… (soft-deprecated) "Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 33

Slide 33 text

UIApplication.shared.connectedScenes ͲͷΠϯελϯε͕ Ͳͷγʔϯͩ…? "Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 34

Slide 34 text

UIApplication.shared.windows ͍ͬͺ͍͋Δͧ…? "Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 35

Slide 35 text

keyWindowͬͯͲΕͩ??? UIApplication.shared.keyWindow ? ? ? ? "Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 36

Slide 36 text

windowScene.windows ͲͷΠϯελϯε ͕Ͳͬͪͩ…? "Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 37

Slide 37 text

windowScene.keyWindow keyWindowͬͯͲΕͩ??? ? ? "Apple Studio Display Free Mockups" © BRIX Templates (Licensed under CC BY 4.0) "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 38

Slide 38 text

αΠζΛͲ͏औಘ͢Δ͔ • ྫ͑͹ • ֎෦σΟεϓϨΠ઀ଓ࣌ʹࣗ෼ࣗ਎͕ͲͷσόΠεͷεΫ Ϧʔϯͳͷ͔͸UIScreenͰ͸෼͔Βͳ͍ (αΠζͰ൑அ͢Δͱ ͍͏ख͸͋Δ͕…) • ಉ͡Α͏ʹSplitViewͷࠨଆͷUIWindowScene͕ͲΕͳͷ͔ɻ Έ͍ͨͳࣄ͸connectedScenes͔Β͸෼͔Βͳ͍ 38

Slide 39

Slide 39 text

αΠζΛͲ͏औಘ͢Δ͔ 39 UIViewͷํ޲͔Βॱ൪ʹḷΔͷ͕ྑ͍

Slide 40

Slide 40 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 41

Slide 41 text

view.window @MainActor class UIView : UIResponder { var window: UIWindow? { get } } "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 42

Slide 42 text

@MainActor class UIWindow : UIView { weak var windowScene: UIWindowScene? { get set } } window.windowScene "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 43

Slide 43 text

@MainActor class UIWindowScene : UIScene { var screen: UIScreen { get } } windowScene.screen "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 44

Slide 44 text

αΠζΛͲ͏औಘ͢Δ͔ 44 UIViewͷํ޲͔Βॱ൪ʹḷΔͷ͕ྑ͍ • UIView͔Βॱ൪ʹḷΔ͜ͱͰରԠ͢Δ্ҐΫϥεΛऔಘͰ͖Δ • UIView 1 — 0…1 UIWindow • UIWindow 1 — 0..1 UIWindowScene • UIWindowScene 1 — 1 UIScreen (SwiftUIʹ͍ͭͯ͸ޙ΄Ͳ)

Slide 45

Slide 45 text

UIWindowͷදࣔํ๏ͱಛੑʹ͍ͭͯ 45

Slide 46

Slide 46 text

UIWindowͷ׆༻ • UIView (UIViewController) Ͱ͸ͳ͘΢Οϯυ΢ͷϨΠϠʔͰॏͳ ΓΛ؅ཧͰ͖Δ • άϩʔόϧʹը໘࠷લ໘ʹཁૉΛදࣔ͢Δͷʹར༻Ͱ͖Δ • શը໘ϩʔσΟϯάͷදࣔ • τʔετͷදࣔ • σόοάπʔϧͷදࣔͳͲ 46

Slide 47

Slide 47 text

47 UIWindowͷॏͳΓͰ ProgressΛ࣮૷ UIViewͷॏͳΓͰ ProgressΛ࣮૷ "iPhone mockups" © Clément Diouloufet (Licensed under CC BY 4.0)

Slide 48

Slide 48 text

UIWindowͷ׆༻ • ཁૉΛॏͶΔ͚ͩͳΒUIViewͷaddSubViewͰ্ʹॏͶͨΓɺ SwiftUIͷ ZStack / overlay ͕͋Δ • ྫ͑͹ UIViewContoller Λpresentͨ͠ΓSwiftUIͰsheetΛදࣔ͠ ͨΓ͢Δͱɺը໘࠷લ໘Ͱ͸ͳ͘ͳͬͯ͠·͏ • ৗʹը໘࠷લ໘ʹද͍ࣔͨ࣌͠ʹUIWindow͕ศར 48

Slide 49

Slide 49 text

UIWindowͷදࣔ • UIWindowͷදࣔ͸UIViewͷΑ͏ʹ addSubView(_:) ͢Δܗࣜͱ ͸গ͠ҟͳΔ 49

Slide 50

Slide 50 text

UIWindowͷදࣔ 50 final class SceneDelegate: UIResponder, UIWindowSceneDelegate{ var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } // ᶃ Πϯελϯεͷੜ੒ let window = UIWindow(windowScene: windowScene) // ᶄ rootViewControllerͷઃఆ window.rootViewController = CustomViewController() // ᶅ UIWindowͷදࣔ window.makeKeyAndVisible() // ᶆ Πϯελϯεͷอ࣋ self.window = window } }

Slide 51

Slide 51 text

makeKeyAndVisibleʹ͍ͭͯ 51

Slide 52

Slide 52 text

makeKeyAndVisibleʹ͍ͭͯ 52

Slide 53

Slide 53 text

makeKeyAndVisibleͷޡղ • makeKeyAndVisible() ͸ɺUIWindowΛΩʔ΢Οϯυ΢ (isKeyWindow: true) ʹͯ͠UIWindowΛදࣔঢ়ଶʹ͢Δॲཧ • Ωʔ΢Οϯυ΢ʹͳΔ͜ͱͰը໘࠷લ໘ʹදࣔ͞ΕΔͱࢥΘ ΕΔ͜ͱ͕͋Δ͕ɺ௚઀͸ؔ܎ͳ͍ 53

Slide 54

Slide 54 text

UIWindowΛը໘࠷લ໘ʹදࣔ͢Δʹ͸ • Z࣠ࢦఆ͢Δͷʹ windowLevel: UIWindow.Level ͕͋Δ • windowLevel ͷߴ͍ॱʹલ໘ͱͳ͍ͬͯΔ • public init(_ rawValue: CGFloat) • UIWindow.Level (.normal / .alert / .statusBar) 54

Slide 55

Slide 55 text

UIWindowΛը໘࠷લ໘ʹදࣔ͢Δʹ͸ • windowLevel ͕ಉ͡UIWindowؒͷલޙ͸Ͳ͏ܾ·͍ͬͯΔʁ • isKeyWindow ͕ઌ಄Λอূ͢Δ΋ͷͰ͸ͳ͍ • UIApplication.shared.windows ͷ߱ॱͰ΋ͳ͍ • windowScene.windows ͷ߱ॱͰ΋ͳ͍ 55

Slide 56

Slide 56 text

UIWindowΛը໘࠷લ໘ʹදࣔ͢Δʹ͸ • windowLevel ͕ಉ͡UIWindowؒʹ͓͚Δදࣔॱ • ৽͘͠ visible ঢ়ଶʹͳͬͨUIWindow΄Ͳલʹදࣔ͞ΕΔ 56

Slide 57

Slide 57 text

UIWindowΛը໘࠷લ໘ʹදࣔ͢Δʹ͸ • windowLevel ͕ಉ͡UIWindowؒʹ͓͚Δදࣔॱ • ৽͘͠ visible ঢ়ଶʹͳͬͨUIWindow΄Ͳલʹදࣔ͞ΕΔ 57 UIWindow ͷ visibility ʹมߋ͕͋ͬͨࡍʹ UIWindow.didBecomeVisibleNotification Ͱߋ৽͞Εͨ UIWindow ͕௨஌͞ΕΔͷͰɺ͜Εͷ௨஌͕࠷ޙʹ͞Εͨ΋ͷ*1 *1: Undocumented ͕ͩɺprivate APIΛίʔϧͯ͠ௐ΂ͯΈͨײ͓ͦ͡Β࣮͘ࡍͷදࣔॱܾఆ͸ UIScene ͕ ಺෦Ͱอ͍࣋ͯ͠Δ NSArray *_visibleWindows ॱʹͳ͍ͬͯͦ͏

Slide 58

Slide 58 text

Ωʔ΢Οϯυ΢ͱ͸ • UIWindowScene͝ͱʹҰ͚ͭͩଘࡏ͢Δ isKeyWindow ͷ஋͕ true ͱͳ͍ͬͯΔUIWindow • ΩʔೖྗΛड͚෇͚ΒΕΔUIWindow • ࠲ඪ஋Λ࣋ͨͳ͍ΠϕϯτΛ௨஌͢ΔͨΊʹ࢖ΘΕΔ 58

Slide 59

Slide 59 text

59 UIWindow1 UIWindow2 UIWindow3 "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0)

Slide 60

Slide 60 text

60 UIWindow1 UIWindow2 UIWindow3 "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0) "Mac Keyboard Mockup for Figma" © ͋͛ (Licensed under CC BY 4.0) ? ? ?

Slide 61

Slide 61 text

61 UIWindow1 UIWindow2 UIWindow3 "iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0) "Mac Keyboard Mockup for Figma" © ͋͛ (Licensed under CC BY 4.0) isKeyWindow: false isKeyWindow: false isKeyWindow: true isKeyWindow: true

Slide 62

Slide 62 text

Ωʔ΢Οϯυ΢ͱ͸ • ը໘ͷλοϓ΍Ϛ΢εϗόʔͳͲ͸࠲ඪ஋Λ࣋ͭΠϕϯτ • λοϓҐஔʹଘࡏ͢ΔUIWindow͕ΠϕϯτΛड͚औΔ • ΩʔϘʔυೖྗͳͲͷ࠲ඪ஋Λ࣋ͨͳ͍Πϕϯτ͸Ωʔ΢Οϯ υ΢͕ड͚औΔ ͨͩ͠Ωʔ΢Οϯυ΢Ҏ֎ͷUIWindow͕ʮ࠲ඪ஋Λ࣋ͭΠϕϯ τʯड͚औΔͱΩʔ΢Οϯυ΢͸ҠΓมΘΔͷͰ஫ҙ 62

Slide 63

Slide 63 text

ͦͷଞͷؾΛ͚ͭΔ΂͖UIWindowͷಛੑက • ྫ͑͹ϑϨʔϜͷڍಈ • UIWindowͷ frame.size ͕UIWindowSceneͷ coordinateSpace.bounds.size ͱಉ͡৔߹ • ʮશը໘දࣔʯ͞Ε͍ͯΔͱΈͳ͞ΕΔ 63

Slide 64

Slide 64 text

"iPad Pro Mockup" © Eduard (Licensed under CC BY 4.0) 64

Slide 65

Slide 65 text

ͦͷଞͷؾΛ͚ͭΔ΂͖UIWindowͷಛੑက • ʮશը໘දࣔʯ͞Ε͍ͯΔ৔߹ • frame.origin ʹͲΜͳ஋Λઃఆͯ͠΋ CGPoint.zero Ͱ্ॻ͖͞ Εͯ͠·͏ 65

Slide 66

Slide 66 text

ͦͷଞͷؾΛ͚ͭΔ΂͖UIWindowͷಛੑက • ྫ͑͹εςʔλεόʔͷڍಈ • εςʔλεόʔͷදࣔɾඇදࣔ͸ʮશը໘දࣔ͞Ε͍ͯΔʯ UIWindowͷ͏ͪʮ࠷લ໘දࣔʯ͞Ε͍ͯΔUIWindowʹඥͮ ͘rootViewControllerͷ prefersStatusBarHidden ʹӨڹΛड͚ Δ 66

Slide 67

Slide 67 text

ͦͷଞͷؾΛ͚ͭΔ΂͖UIWindowͷಛੑက 67 final class CustomViewController: UIViewController { private var isHidden: Bool override var prefersStatusBarHidden: Bool { return isHidden } init(isHidden: Bool, color: UIColor?) { self.isHidden = isHidden super.init(nibName: nil, bundle: nil) view.backgroundColor = color } @available(*, unavailable) required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }

Slide 68

Slide 68 text

68 @main class AppDelegate: UIResponder, UIApplicationDelegate { var windows: [UIWindow] = [] func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]?) -> Bool { let blueWindow = UIWindow(frame: UIScreen.main.bounds) blueWindow.rootViewController = CustomViewController(isHidden: false, color: .blue) blueWindow.windowLevel = .init(2) blueWindow.isHidden = false windows.append(blueWindow) let redWindow = UIWindow(frame: UIScreen.main.bounds) // ΑΓલ໘ʹ࠷લ໘දࣔ͞ΕͨblueWindow͕͍ΔͷͰεςʔλεόʔ͸ӅΕͳ͍ redWindow.rootViewController = CustomViewController(isHidden: true, color: .red) redWindow.windowLevel = .init(1) redWindow.isHidden = false windows.append(redWindow) let greenWindow = UIWindow(frame: .init(x: 20, y: 20, width: 100, height: 100)) // ࠷લ໘ʹදࣔ͞Ε͍ͯΔ͕શը໘දࣔ͞Ε͍ͯͳ͍ͷͰεςʔλεόʔ͸ӅΕͳ͍ greenWindow.rootViewController = CustomViewController(isHidden: true, color: .green) greenWindow.windowLevel = .init(3) greenWindow.isHidden = false windows.append(greenWindow) return true } }

Slide 69

Slide 69 text

SwiftUIͰͷUIWindowදࣔʹ͍ͭͯ 69

Slide 70

Slide 70 text

SwiftUIͰUIWindowΛऔಘ͢Δ • 1: App಺ͷView͔Βऔಘ͢Δ৔߹ • 2: App֎Ͱ࡞੒ͨ͠UIWindowʹඥͮ͘SwiftUIͷView͔Βऔಘ͢ Δ৔߹ 70

Slide 71

Slide 71 text

App಺ͷView͔Βऔಘ͢Δ৔߹ • App಺ͷView͔ΒUIWindowΛऔಘ͍ͨ͠৔߹ObservableObject ͳSceneDelegateΛར༻͢Δͱྑ͍ 71

Slide 72

Slide 72 text

1: App಺ͷView͔Βऔಘ͢Δ৔߹ 72 @main struct SampleAppApp: App { // UIApplicationDelegateAdaptorΛར༻͢Δ @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate var body: some Scene { WindowGroup { ContentView() } } } final class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { let configuration = UISceneConfiguration(name: nil, sessionRole: connectingSceneSession.role) if connectingSceneSession.role == .windowApplication { configuration.delegateClass = SceneDelegate.self } return configuration } }

Slide 73

Slide 73 text

1: App಺ͷView͔Βऔಘ͢Δ৔߹ 73 final class SceneDelegate: UIResponder, UIWindowSceneDelegate, ObservableObject { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } self.window = windowScene.keyWindow // γʔϯͷ઀ଓ࣌ʹ͸keyWindowΛͱͬͯ໰୊ͳ͍ (UIWindow͕Ұ͚ͭͩͳͷͰ) } }

Slide 74

Slide 74 text

1: App಺ͷView͔Βऔಘ͢Δ৔߹ 74 struct ContentView: View { @EnvironmentObject var sceneDelegate: SceneDelegate var body: some View { // EnvironmentObject͔Βऔಘͨ͠sceneDelegateΛར༻ͯ͠ sceneDelegate.window͕ར༻Ͱ͖Δ } }

Slide 75

Slide 75 text

2: App֎Ͱ࡞੒ͨ͠UIWindowͷ৔߹ 75 extension UIWindow: ObservableObject {} final class SceneDelegate: NSObject, UIWindowSceneDelegate{ var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } let window = UIWindow(windowScene: windowScene) // environmentObjectͰUIWindowΛ౉ͯ͋͛͠Δ window.rootViewController = UIHostingController(rootView: OverlayView().ignoresSafeArea().environmentObject(window)) window.isHidden = false self.window = window } }

Slide 76

Slide 76 text

2: App֎Ͱ࡞੒ͨ͠UIWindowͷ৔߹ 76 struct OverlayView: View { @EnvironmentObject var window: UIWindow var body: some View { // EnvironmentObject͔Βऔಘͨ͠window͕ར༻Ͱ͖Δ } }

Slide 77

Slide 77 text

UIWindowSceneͷαΠζ͕มΘͬͨ͜ͱΛݕ஌͍ͨ͠ • windowScene ͷ delegate ϝιουʹ↓͕͋Δ windowScene(_:didUpdate:interfaceOrientation:traitCollection:) • ͜Ε࢖͑ͦ͏ͳؾ΋͢Δ͕… 77

Slide 78

Slide 78 text

UIWindowSceneͷαΠζ͕มΘͬͨ͜ͱΛݕ஌͍ͨ͠ • windowScene(_:didUpdate:interfaceOrientation:traitCollection:) • UIApplicationDelegateAdaptorܦ༝ͷ৔߹͸͜ͷdelegateϝιο υ͸ݺ͹Εͳ͍ • UISceneConfigurationͷdelegateClassʹઃఆͨ͠ SceneDelegate͕ͦͷ··࢖ΘΕΔΘ͚Ͱ͸ͳ͘ɺ SwiftUI.AppSceneDelegate͕಺෦తʹར༻͞ΕΔͨΊ 78

Slide 79

Slide 79 text

UIWindowSceneͷαΠζ͕มΘͬͨ͜ͱΛݕ஌͍ͨ͠ • WindowGroup ͷ௚Լʹ GeometryReader Λઃஔ͢Δ͔͠ͳ͍͔ ΋… 79

Slide 80

Slide 80 text

·ͱΊ • UIWindow΍UIWindowSceneͷαΠζ͕ཉ͍͠৔߹͸ΑΓԼҐ ͷΫϥε͔Βٯॱʹḷ͍ͬͯ͘ͱྑ͍ • UIWindowͷදࣔॱܾఆ͸UIViewͱ͸ҧ͍ͬͯΔͷͰ஫ҙ͕ඞ ཁɻεςʔλεόʔͷදࣔͷڍಈ΋ॱ൪͕Өڹ͢Δ • SwiftUI͔ΒUIWindowʹΞΫηε͍ͨ͠৔߹͸ UIApplicationDelegateAdaptorΛ࣮૷͢ΔͱEnvironmentObjectܦ ༝ͰऔಘͰ͖Δ 80