TabBarController:以不同方向定向视图 [英] TabBarController: Orienting views in different orientations
问题描述
我无法保留当前的观看方向。在下面的设置中,我能够将第一个视图控制器锁定为纵向,将第二个视图控制器锁定为横向或纵向。但是,当我向选项卡控制器添加第二个导航控制器/ rootviewcontroller时,整个项目中的所有视图都将同时显示为横向和纵向。无论我是否在第一个导航控制器中将相同的代码实现到第二个导航控制器,都会发生这种情况
I am having trouble preserving my current views orientation. In the below setup, I have been able to lock the first view controller to portrait and the second viewcontroller to landscape or portrait. However, when I add a second navigation controller/rootviewcontroller to the tab controller, all of the views throughout the project will go to both landscape and portrait. This happens regardless of if I implement the same code in the first navigation controller to the second nav controller or not
我希望能够保留当前查看控制器方向,同时添加额外的navcontroller> viewcontroller
我在故事板中进行了以下设置:
I have the following setup in storyboard:
这就是我想要实现的目标:
< img src =https://i.stack.imgur.com/YEz40.pngalt =在此处输入图像说明>
This is what I am trying to achieve:
tabbarcontroller的位置应支持所有方向,导航控制器支持所有方向,第一个视图控制器和表视图控制器仅支持纵向,第二个视图控制器支持横向和纵向。
以下是每个当前视图控制器的方法
And here are the methods for each of the current view controllers
TabViewController.m
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
NavController.m
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
First View Controller.m
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
Second View Controller.m
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
非常感谢您解决此问题的任何帮助。它已经成为我生存的祸根
推荐答案
看来你已经将一个tabbar控制器子类化了。而不是这样做,你可以在运行时控制方向只使用他们的委托协议。
It seems that you've subclassed both navigation an tabbar controller. Instead of doing that you can control at runtime the orientations just using their delegation protocol.
– tabBarControllerSupportedInterfaceOrientations:
– tabBarControllerPreferredInterfaceOrientationForPresentation:
和
– navigationControllerPreferredInterfaceOrientationForPresentation:
– navigationControllerSupportedInterfaceOrientations:
你可以把我认为那些方法中的逻辑对于更清晰的实现更好,而不是子类化。容器视图控制器通常接管单个vc旋转实现。
You can put your logic in those method I think that would be better for having a more clear implementation, instead of subclassing. Container view controllers usually take over about single vc rotations implementations.
这篇关于TabBarController:以不同方向定向视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!