我在纵向模式下有十多个ViewControllers,但无论设备的方向如何,我都需要在横向模式下强制使用一个.
Fed*_*olo 12
这是解决方案:
1)将LandscapeViewController嵌入子类NavigationController中,并使用模态segue从PortraitViewController连接它.

2)子类UINavigationController
LandscapeNavigationController.m
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft;
}
Run Code Online (Sandbox Code Playgroud)
3)不要忘记解雇你的模态VC(在这种情况下从我的Bar Buttom Item Action)
- (IBAction)goBack:(id)sender
{
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)