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.
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.
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.
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.
GeometryReader3D
isn't even working to give the window size of a volumetric window: #77971199 –
Aquarius © 2022 - 2025 — McMap. All rights reserved.
SwiftUI.Layout
orGeometryReader
depending on the scenario – Strauss