
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
How to lock Screen Orientation programmatically in iOS?
You might come across a scenario where you need to show the UI in a specific orientation may be Landscape or Portrait.
We will be seeing how to lock orientation programmatically using Swift in iOS.
Open Xcode → New Project → ViewController.swift write the below code.
// Set the shouldAutorotate to False override open var shouldAutorotate: Bool { return false } // Specify the orientation. override open var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait }
- Related Articles
- How to lock screen orientation on all android devices programmatically?
- How to lock & unlock the iOS device programmatically
- How to change screen brightness programmatically in iOS?
- How to change Screen Orientation programmatically using a Button in Android?
- How to change Screen Orientation programmatically using a Button in Android Kotlin?
- Disable Orientation Change in iOS
- How to lock the Android device programmatically?
- How to answer incoming call programmatically in iOS?
- How to get screen DPI programmatically in Android?
- How to change screen brightness programmatically in android?
- How to take a screenshot programmatically in iPhone/iOS?
- How to enable/disable data connection in iOS programmatically?
- How to create Picker programmatically from array in iOS?
- How to programmatically prevent scrolling in WebView of iOS?
- How to make an application ignore screen orientation change in Android?

Advertisements