ios - 标签栏 Controller : Orienting views in different orientations

标签 ios objective-c ios7 uinavigationcontroller uitabbarcontroller

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

我希望能够在添加额外的 navcontroller>viewcontroller 的同时保留我当前的 View Controller 方向

我在 Storyboard中有以下设置: enter image description here

这就是我要实现的目标: enter image description here

tabbarcontroller 应该支持所有方向,nav Controller 支持所有方向,第一个 View Controller 和表格 View Controller 只支持纵向,第二个 View Controller 支持横向和纵向。

这里是每个当前 View Controller 的方法

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

第二 View Controller .m

-(BOOL)shouldAutorotate

{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}


- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{

    return UIInterfaceOrientationLandscapeLeft;
}

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

最佳答案

看来您已经将导航和标签栏 Controller 都进行了子类化。您可以在运行时仅使用委托(delegate)协议(protocol)来控制方向,而不是这样做。

– tabBarControllerSupportedInterfaceOrientations:
– tabBarControllerPreferredInterfaceOrientationForPresentation:

– navigationControllerPreferredInterfaceOrientationForPresentation:
– navigationControllerSupportedInterfaceOrientations:

您可以将您的逻辑放在那些方法中,我认为这会更好地实现更清晰的实现,而不是子类化。容器 View Controller 通常接管单个 vc 旋转实现。

关于ios - 标签栏 Controller : Orienting views in different orientations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24479184/

相关文章:

ios - 在 swift 中使用 tableview 和数组过滤器自动完成文本字段

iphone - 向 iOS 应用添加 "Open In..."选项

ios - 在 iOS 中解析 JSON 时出现 NSSingleObjectArrayI 错误?

objective-c - 如何为 iOS 应用程序创建 objective-C 框架

objective-c - 如何以编程方式使用 Cocoa 获取当前电池电量

ios - 检查此运行中是否已打开 View

ios - 如何增加颜色空间CAGradientLayer

ios - 运动事件在iOS中处于挂起状态

ios7 - 旋转后 topLayoutGuide 未更新

iOS - 不确定如何正确更新 iOS 7 的 cocoapods 配置