DEV Community

Fabio Floris
Fabio Floris

Posted on

A Modern SwiftUI Technique for Detecting Device Orientation

Detecting whether your app is in portrait or landscape sounds simple, until you try it in SwiftUI.
With UIScreen.main deprecated in iOS 18 and size classes still inconsistent on iPad, many devs end up with unpredictable layouts or broken keyboard behavior.

I wrote a full breakdown of a reusable approach using window geometry updates.
The initial spark came from a great example shared by Artem Mirzabekian.

Inside the article:

  • why SwiftUI struggles with orientation
  • pitfalls of relying on size classes
  • building a modern ViewModifier for window tracking
  • exposing orientation via an environment value
  • complete code + reasoning

👉 Read the full article: A Reusable OrientationReader for SwiftUI (that doesn’t break when the keyboard appears)

If you're building responsive SwiftUI interfaces, this might save you some time.

Top comments (0)