How to maintain presenting view controller's orientation when dismissing modal view controller?

前端 未结 9 2142
礼貌的吻别
礼貌的吻别 2020-11-30 03:57

I have this app I am working on and I need ALL my view controllers but one to be in portrait. The single one view controller that is special I need it to be able to rotate t

9条回答
  •  误落风尘
    2020-11-30 04:20

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
    if ([self.window.rootViewController.presentedViewController isKindOfClass: [SecondViewController class]])
    {
        SecondViewController *secondController = (SecondViewController *) self.window.rootViewController.presentedViewController;
    
        if (secondController.isPresented)
            return UIInterfaceOrientationMaskAll;
        else return UIInterfaceOrientationMaskPortrait;
    }
    else return UIInterfaceOrientationMaskPortrait;
    }
    

    And for Swift

    func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow) -> Int {
    
        if self.window?.rootViewController?.presentedViewController? is SecondViewController {
    
            let secondController = self.window!.rootViewController.presentedViewController as SecondViewController
    
            if secondController.isPresented {
                return Int(UIInterfaceOrientationMask.All.toRaw());
            } else {
                return Int(UIInterfaceOrientationMask.Portrait.toRaw());
            }
        } else {
            return Int(UIInterfaceOrientationMask.Portrait.toRaw());
        }
    
    }
    

    For more details check this link

提交回复
热议问题