5

My app is designed to work in Portrait and in landscape orientations. Starting with iOS 8 there is a problem starting the app if the device is held in landscape orientation. The UI is simply not correct initialized.

My Users have to close the app and start again while holding the device in portrait.

How can I arrange that the app is always launching in portrait mode without locking it to this mode? After this the user should be allowed to change to all four orientations.

In my view controller shouldAutorotate returns true, and supportedInterfaceOrientations returns all.

thpitsch
  • 2,016
  • 2
  • 21
  • 27
  • Are you setting your UIViewController as rootViewController? – Nitheesh George Mar 31 '15 at 06:51
  • When you are designing app for both the orientations you must work for Landscape orientation as well so that a user opening app in Landscape can also use app without any issue. – Suraj Mirajkar Mar 31 '15 at 07:10
  • do you have all splash screens for landscape and portrait? Sometimes it makes this. – kocakmstf Mar 31 '15 at 07:18
  • The root viewcontroller is a tabcontroller. – thpitsch Mar 31 '15 at 08:01
  • I've made the work for landscape also. And it is working fine since iOS 4. The problem is an error in iOS 8 which causes the wrong initialization in landscape. I have to start in portrait. The user then have to change the orientation to portrait and maybe back to landscape. I have splash screens for both orientations. – thpitsch Mar 31 '15 at 08:05
  • have you checked the return value of UIDeviceOrientationIsLandscape API? – Nitheesh George Mar 31 '15 at 09:11
  • UIDeviceOrientation Is Landscape when the user hold the device in landscape. But if I start the app in this orientation, the initialization is wrong. In this state, also the portrait view is wrong after changing the direction. Only when the app is starting in portrait, then the init is also good for landscape. So I want to init in portrait only one time but let the user change the orientation later. – thpitsch Mar 31 '15 at 09:22
  • On www.clickthai-online.com/Test/test.html you can see screenshots of the problem. It's a serious problem and a bug in iOS – thpitsch Mar 31 '15 at 10:54
  • 1
    This should work https://stackoverflow.com/a/50620871/4320266 – Gürhan KODALAK May 31 '18 at 09:23

2 Answers2

1

Heres a solution that worked for me on ios 11, my app supports Portrait and landscape but the initial view has tab bar that must be in portrait always. Set orientation lock and create a Utility that you should be executed inside didFinishLaunchingWithOptions like this :

AppUtility.lockOrientation(.portrait)

    func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return self.orientationLock
}

struct AppUtility {
    static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
        if let orientationDelegate = UIApplication.shared.delegate as? AppDelegate {
            orientationDelegate.orientationLock = orientation
        }
    }
Sergio Trejo
  • 632
  • 8
  • 23
-2

Click the project name in project navigator. Then go to general and to deployment options section choose your preferred device orientation

enter image description here

  • With this the app runs only in portrait and the user can't change to landscape. That's not what I want. – thpitsch Mar 31 '15 at 09:07