# Viewcontroller Orientation Problem

**URL:** <https://ifnotnil.com/t/viewcontroller-orientation-problem/3723>\
**Category:** Swift\
**Created:** [30 November 2023 16:51 UTC](https://ifnotnil.com/t/viewcontroller-orientation-problem/3723 "2023-11-30T16:51:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [30 November 2023 16:51 UTC](https://ifnotnil.com/t/viewcontroller-orientation-problem/3723/1 "2023-11-30T16:51:13Z")

</div>

I am attempting to create an iPhone app with two VIEW… one should always be PORTRAIT, the other ALWAYS Landscape (regardless of the orientation of the device)

All the websites I read basically say “easy-peasy”, just do this… and THIS is different in each case

I have tried this on each ViewController (the other one says .portrait)

```auto
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { return .landscapeLeft}
    override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .landscapeLeft}
    override var shouldAutorotate : Bool { return false }

```

and the display STARTS out fine… but if I do rotate the device, the view rotates and it shouldn’t  
they need to remain locked to the orientation specified

this is in Appdelegate

```auto
  func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        return [.portrait,.landscapeLeft]
     }

```

either orientation works fine if I only have ONE value specified here, but the other view then crashes

---

<div class="post-metadata">

**Author:** ![DaveS](https://ifnotnil.com/user_avatar/ifnotnil.com/daves/32/79_2.png) [@DaveS](https://ifnotnil.com/u/DaveS)\
**Post date:** [30 November 2023 17:12 UTC](https://ifnotnil.com/t/viewcontroller-orientation-problem/3723/2 "2023-11-30T17:12:48Z")

</div>

This seems like a hack, but for now it works

```auto
  func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
        if current$View == "view2" {
            return [.landscapeLeft]
        } else {
            return [.portrait]
        }
     }

```

current$View is updated by each view
