How do I get the window size in visionOS?
Asked Answered
B

2

6

Is there something similar to UIScreen.main.bounds on visionOS?

I have some code that depends on the screen size and using a hard coded value for it doesn’t really work out unfortunately.

Biliary answered 16/7, 2023 at 13:29 Comment(3)
Have you tried utilizing GeometryReaderPia
Use SwiftUI.Layout or GeometryReader depending on the scenarioStrauss
I'd recommend to look into containerRelativeFrame for iOS 17+ and visionOS developer.apple.com/documentation/deviceactivity/…Jeb
S
2

This doesn't exist on visionOS. UIScreen and UIWindow are different classes on iOS, and while there are UIWindows on visionOS, there's no analog of UIScreen (the class itself in marked unavailable). The visionOS 'screen' is not really measured in points, but in degrees of field-of-view, and as such, you can't really convert between the two. You can always get the size of the current window by using a GeometryReader.

Scullion answered 20/7, 2023 at 9:34 Comment(0)
H
2

Apple's official documentation states that the default window size in visionOS is 1280x720 pt. At the moment, there is no way to measure visionOS window size using .bounds property, however, to measure the size, you can use GeometryReader3D.

var body: some View {
    GeometryReader3D { proxy3D in
        VStack {
            RealityView { content in
                // code here...
            }
        }
        .onAppear {
            Task {
                try await Task.sleep(nanoseconds: 1_000_000_000)
                print("The size is:", proxy3D.size)
            }
        }
    }
}

//  The size is: (width: 1280.0, height: 720.0, depth: 540.0)

P. S.

A default size for a volumetric window is 1280x1280x1280 pt.

Hypocycloid answered 3/10, 2023 at 10:17 Comment(1)
For me GeometryReader3D isn't even working to give the window size of a volumetric window: #77971199Aquarius

© 2022 - 2025 — McMap. All rights reserved.