UIWindow's root view controller does not rotate to landscape at app launch

前端 未结 2 1137
小蘑菇
小蘑菇 2021-01-07 07:29

I am developing a xib-based landscape-only app. The app launches in landscape correctly. However, the view in my main ViewController is presented in portrait. That is, it is

相关标签:
2条回答
  • 2021-01-07 08:04

    I had this same issue: an app which was meant to be in Landscape that assumed the ViewController was always in Portrait. I made tons of changes to every aspect of the project and info.plist, including giving the main UIWindow a root-view controller which was landscape. It still didn't work. I eventually undid all the changes and just added the two lines noted below to my app delegate:

    - (void)applicationDidFinishLaunching:(UIApplication *)application 
    {
        [_window addSubview:[_viewController view]];
        glView = _viewController.glView;
    
        // THIS FIXED ORIENTATION FOR ME IN IOS 6
        _window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        // END
    
        ...my other setup code here...
    }
    

    Nothing else was necessary.

    It appears that, for some reason, in iOS 6 the UIWindow root-view-controller setting is sometimes ignored in Interface Builder. I am sure my reasoning is wrong somewhere, but I thought this might well help prod someone in the direction of a fuller, more exhaustive answer.

    0 讨论(0)
  • 2021-01-07 08:22

    In iOS 8, settings windows frame to the UIScreen is also necessary, as it won't get automatically updated.

    self.window.frame = [UIScreen mainScreen].bounds;
    
    0 讨论(0)
提交回复
热议问题