【问题标题】:TabBarController: Orienting views in different orientationsTabBarController:以不同方向定位视图
【发布时间】:2014-08-20 04:17:26
【问题描述】:

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

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

我在情节提要中有以下设置:

这就是我想要实现的目标:

tabbarcontroller应该支持所有方向,nav控制器支持所有方向,第一个视图控制器和表格视图控制器只支持纵向,第二个视图控制器支持横向和纵向。

这里是每个当前视图控制器的方法

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;
}

第二视图控制器.m

-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationLandscapeLeft;
}

在解决此问题时,我将不胜感激。它已成为我存在的祸根

【问题讨论】:

    标签: ios objective-c ios7 uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    您似乎已经将导航和标签栏控制器子类化了。您可以在运行时仅使用它们的委托协议来控制方向,而不是这样做。

    – tabBarControllerSupportedInterfaceOrientations:
    – tabBarControllerPreferredInterfaceOrientationForPresentation:
    

    – navigationControllerPreferredInterfaceOrientationForPresentation:
    – navigationControllerSupportedInterfaceOrientations:
    

    你可以把你的逻辑放在那些我认为有一个更清晰的实现而不是子类化的方法中。容器视图控制器通常接管单个 vc 旋转实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-12
      • 2012-01-22
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      相关资源
      最近更新 更多