Post

Replies

Boosts

Views

Activity

Reply to How to get the frame or insets of the new iPadOS 26 window control buttons (close, minimize, fullscreen)?
@Mobiel I was able to use your example to create a UIKit → SwiftUI connection where those layout guide values are available to a SwiftUI view. It works okay. You can see here the red box is in SwiftUI, and it is detecting where the window control is. There is one issue, which is that when the window is returned to full screen, the layout guide is not updating to "0" size for the window control. Not sure if that's an iPadOS beta bug or what. Here is a screenshot: Here is the code: // // ContentView.swift // WindowControlsTest // // Created by MAK on 8/7/25. // import SwiftUI import UIKit struct ContentView: View { @State var offsets = WindowControlDetection() var body: some View { ZStack(alignment: .topLeading) { WindowControlsUIKitViewRepresentable() Rectangle() .foregroundStyle(.red) .frame(width: offsets.leadingInset, height: offsets.topInset) Rectangle() .hidden() .overlay { Text("leading: \(Int(offsets.leadingInset)) top: \(Int(offsets.topInset))") } } .ignoresSafeArea() .environment(offsets) } } @Observable class WindowControlDetection { var leadingInset: CGFloat = 0 var topInset: CGFloat = 0 } class WindowControlsUIKitView: UIView { private let offsets: WindowControlDetection init(offsets: WindowControlDetection) { self.offsets = offsets super.init(frame: .zero) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func layoutSubviews() { super.layoutSubviews() let newLeading = layoutGuide(for: .margins(cornerAdaptation: .horizontal)).layoutFrame.minX let newTop = layoutGuide(for: .margins(cornerAdaptation: .vertical)).layoutFrame.minY DispatchQueue.main.async { [weak offsets] in offsets?.leadingInset = newLeading offsets?.topInset = newTop } } } struct WindowControlsUIKitViewRepresentable: UIViewRepresentable { @Environment(WindowControlDetection.self) var layoutOffsets func makeUIView(context: Context) -> WindowControlsUIKitView { return WindowControlsUIKitView(offsets: layoutOffsets) } func updateUIView(_ uiView: WindowControlsUIKitView, context: Context) { } }
Topic: UI Frameworks SubTopic: UIKit Tags:
Aug ’25
Reply to How to get the frame or insets of the new iPadOS 26 window control buttons (close, minimize, fullscreen)?
I have the same question. WWDC Sessions and the HIG mention "moving your controls" when the window control appears. It's great that this happens automatically when using a standard NavigationStack and standard toolbar, however for apps that are unable to use standard UI elements, the documentation currently makes it sound like there is some way to get this sizing programmatically. Filed FB18559686 Screenshot of the issue: Sample code to make this happen: import SwiftUI struct ContentView: View { var body: some View { VStack(spacing: 0) { HStack { // Trying to make this button respect window controls safe area Button(action: { }, label: { Image(systemName: "xmark") }) .padding() .foregroundStyle(.primary) .glassEffect() Spacer() } .padding() .background(.fill.quaternary) Rectangle() .foregroundStyle(.fill.quinary) } } } #Preview { ContentView() }
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’25