Disable Auto Rotation in SwiftUI
If you are building your app in SwiftUI using Xcode, you might notice that even if your device’s (maybe an iPhone or iPad) portrait orientation lock is turned on, your app will still rotate with your device rotation.
In this SwiftUI tutorial, I will show you how to prevent or disable the auto-rotation of your App. This is also called orientation disabling.
There’s nothing like adding a line of code to do this if you are using Xcode. You just need to uncheck the unwanted orientation boxes from the Deployment info.
Just follow the steps mentioned in the below image:
I have written in the screenshot how to turn off orientation in your SwiftUI project.
Steps are:
- Click on the app name first in your XCode window. (As described in the above image)
- Then click on your App name from the TARGETS.
- Check for Deployment Info and uncheck Landscape Left and Landscape Right.
Now try to run your project. It will not auto-rotate your app no matter if your portrait orientation is locked or not.
Leave a Reply