Trick preferredInterfaceOrientationForPresentation to fire on viewController change

前端 未结 2 1201
天命终不由人
天命终不由人 2021-01-18 04:49

I am using MSNavigationPaneViewController from here and have rotation sort of working. I\'ve overridden the rotation methods in my root UINavigationContro

相关标签:
2条回答
  • 2021-01-18 05:26

    preferredInterfaceOrientationForPresentation will not be called on controllers within a UINavigationController.

    You are going to have to subclass UINavigationController and then implement this feature yourself. You'd simply want to delegated to topViewController.

    For reference check out: http://code.shabz.co/post/32051014482/ios-6-supportedorientations-with-uinavigationcontroller

    I also found this implementation of a UINavigationController subclass: https://gist.github.com/3842178

    0 讨论(0)
  • 2021-01-18 05:34

    You can trick the window into re-valuating its supported interface orientations by resetting its rootViewController.

    UIApplication *app = [UIApplication sharedApplication];
    UIWindow *window = [[app windows] objectAtIndex:0];
    UIViewController *root = window.rootViewController;
    window.rootViewController = nil;
    window.rootViewController = root;
    

    You'd need to make sure that when this code executes, -supportedInterfaceOrientations of the root view controller returns the proper mask (corresponding to how you want to force the orientation).

    Be aware, this hack can cause a quick flash on the screen and glitch any ongoing animations.

    0 讨论(0)
提交回复
热议问题