UINavigationController + shouldAutoRotate + no sub

2019-08-12 18:09发布

I have a navigation driven app. I need that app to rotate. The UINavigationController is the root controller/view in the window. I know (and have experienced why) it is a no-no to subclass UINavigationController. I know all i have to do is insert:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

into the UINavigationController and it will rotate fine.

So my question is: how do I enable rotation on the root view controller (UINavigationController) WITHOUT subclassing it?

2条回答
对你真心纯属浪费
2楼-- · 2019-08-12 18:10

Your UINavigationController inherits from UIViewController - why would using the method you show be a bad thing? It is perfectly legitimate to use a super's method and is the only way I have ever supported rotation in a UINavigationController. Wouldn't subclassing be when you inherit from UINavigationController (and override that method to do something else without calling the super method?)

查看更多
3楼-- · 2019-08-12 18:21

You need to override this method in your rootViewController, not in UINavigationController.

UIViewController *rootViewController = [[MyRootViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[rootViewController release];
查看更多
登录 后发表回答