Lock Screen Orientation in Swift

Updated 27 April 2023


There are a lot of apps nowadays which we want to use in only landscape or portrait mode according to our preference. Today we are going to implement lock screen orientation in swift.

We can set orientation according to our requirement i.e. portrait or landscape. Let’s check how can we implement lock screen orientation in swift.

Step 1: Create a new iOS project & select device orientation as per the requirement in Runner.

Step 2: Add supported Orientation method in App Delegate.

Step 3: Create 2 buttons for selecting the landscape & portrait orientation.

Step 4: Create action outlets for these buttons in view controller.

Step 5: Create a global helper class to adjust the lock & rotate it to the desired orientation.

Step 6: Use lockOrientation method on the button action in the view controller to lock orientation & rotate the screen.



In this article, I have explained how to lock screen orientation, which you can modify and experiment with according to your own.

Thanks for reading this article ❤

If I got something wrong 🙈, let me know in the comments. I would love to improve.

For more interesting blogs check out here – https://mobikul.com/blog/

Reference link: https://www.polpiella.dev/changing-orientation-for-a-single-screen-in-swiftui

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home