0

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.

Mitemmetim
  • 520
  • 3
  • 12
  • Have you tried utilizing [GeometryReader](https://developer.apple.com/documentation/swiftui/geometryreader) – nickreps Jul 16 '23 at 15:35
  • Use `SwiftUI.Layout` or `GeometryReader` depending on the scenario – lorem ipsum Jul 16 '23 at 15:38
  • I'd recommend to look into containerRelativeFrame for iOS 17+ and visionOS https://developer.apple.com/documentation/deviceactivity/deviceactivityreport/containerrelativeframe(_:alignment:) – fruitcoder Jul 21 '23 at 14:32

1 Answers1

1

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.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172