Search code examples
iosiphoneswiftiphone-x

Retain the portrait position of the iPhone X home indicator


Is there a way to show the home indicator in its portrait position even if the screen orientation is landscape?


Solution

  • As @the4kman pointed out, the only way to achieve this, is by using view transformation:

    view.transform = CGAffineTransform(rotationAngle: .pi / 2)
    

    But also, the view that should be transformed should be an inner view. which you need to set its height equal to the superview width and its width equal to the superview height. And it should be centered vertically and horizontally.

    enter image description here

    You can support all orientations in your app and only disable it for that specific controller.

    The view controller implementation:

    import UIKit
    
    class PortraitController: UIViewController {
    
        @IBOutlet weak var viewLandscaped: UIView!
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            viewLandscaped.transform = CGAffineTransform(rotationAngle: .pi / 2)
        }
    
        override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
            return .portrait
        }
    }
    

    Results:

    enter image description here enter image description here