Ios TabBarController:以不同方向定向视图

Ios TabBarController:以不同方向定向视图,ios,objective-c,ios7,uinavigationcontroller,uitabbarcontroller,Ios,Objective C,Ios7,Uinavigationcontroller,Uitabbarcontroller,我在保留当前视图方向时遇到问题。在下面的设置中,我可以将第一个视图控制器锁定为纵向,将第二个视图控制器锁定为横向或纵向。但是,当我将第二个导航控制器/rootviewcontroller添加到选项卡控制器时,整个项目中的所有视图都将转到横向和纵向。无论我是否在第一个导航控制器到第二个导航控制器中实现相同的代码,都会发生这种情况 我希望在添加额外的navcontroller>viewcontroller时能够保留当前视图控制器的方向 我在故事板中有以下设置: 这就是我努力实现的目标: 其中Ta

我在保留当前视图方向时遇到问题。在下面的设置中,我可以将第一个视图控制器锁定为纵向,将第二个视图控制器锁定为横向或纵向。但是,当我将第二个导航控制器/rootviewcontroller添加到选项卡控制器时,整个项目中的所有视图都将转到横向和纵向。无论我是否在第一个导航控制器到第二个导航控制器中实现相同的代码,都会发生这种情况

我希望在添加额外的navcontroller>viewcontroller时能够保留当前视图控制器的方向

我在故事板中有以下设置:

这就是我努力实现的目标:

其中Tabbar控制器应支持所有方向,导航控制器支持所有方向,第一视图控制器和桌视图控制器仅支持纵向,第二视图控制器支持横向和纵向。

下面是每个当前视图控制器的方法

TabViewController.m

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationLandscapeLeft;
}
NavController.m

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationLandscapeLeft;
}
第一视图控制器.m

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationLandscapeLeft;
}
第二视图控制器.m

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationLandscapeLeft;
}

如果您能帮助我解决这个问题,我将不胜感激。它已成为我生存的祸根

看来您已经将导航和选项卡栏控制器都分为子类。不需要这样做,您可以在运行时仅使用方向的委派协议来控制方向。

– tabBarControllerSupportedInterfaceOrientations:
– tabBarControllerPreferredInterfaceOrientationForPresentation:

您可以将您的逻辑放在这些方法中,我认为这样做会更好,因为有一个更清晰的实现,而不是子类化。容器视图控制器通常接管单个vc旋转实现