iOS 7+ Dismiss Modal View Controller and Force Portrait Orientation

前端 未结 3 1208
时光说笑
时光说笑 2021-02-05 14:13

I have a UINavigationController as the root view controller of my UIWindow on iOS 7 and iOS 8. From one of its view controllers, I present a fullscreen modal view controller wit

3条回答
  •  抹茶落季
    2021-02-05 14:56

    I ended up subclassing the UINavigationController and overriding its rotation methods. The following solution works on iOS 7, but I believe there is a bug in iOS 8 beta 5 that causes the presenting view controller's view to shrink to half the screen-height after dismissing the modal in landscape orientation.

    UINavigationController subclass:

    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return UIInterfaceOrientationPortrait;
    }
    

提交回复
热议问题