我将 UINavigationController 子类化如下:
-(NSUInteger)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate {
return self.topViewController.shouldAutorotate;
}
但是,我无法以与其父级不同的初始方向推动视图控制器。在我的情况下,父视图只是纵向的:
-(BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
但我希望推送的视图仅是横向的 - 它只会在手动更改设备的方向后才会如此。
-(BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
我非常感谢任何人指出我正确的方向。(到目前为止,我只有一个 hacky 解决方案......)
编辑:
以下显示了我如何启动子类 UINavigationController
PortraitView *vc = [[PortraitView alloc] init];
SubClassedNav *navController = [[SubClassedNav alloc] initWithRootViewController:vc];
[navController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:navController animated:YES completion:nil];
以及我随后如何推动新观点:
LandscapeView *vc = [[LandscapeView alloc] init];
[[self navigationController] pushViewController:vc animated:YES];