ios - 带有导航 Controller 方向的标签栏 Controller ios 6

标签 ios uinavigationcontroller ios6 uitabbarcontroller

我目前正在开发一个项目,其中我们有一个带有 4 个选项卡的选项卡栏 Controller ,每个选项卡都有一个导航 Controller 。每个导航 Controller 上都有多个 View Controller 。

我在这里和其他地方读了很多帖子,我们目前做了以下工作:

子类化 UITabbarcontroller

- (BOOL)shouldAutorotate
{

    return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotate];

}

- (NSUInteger) supportedInterfaceOrientations
{
    return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController]supportedInterfaceOrientations];
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return [[[self.viewControllers objectAtIndex:self.selectedIndex]topViewController] shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}

如果我们在每个 View Controller 中指定以下内容,则效果很好:

- (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}

这将按预期将其锁定为纵向。

但是现在真正的问题出现了! 如果我们在其中一个选项卡上的 View Controller 中指定它应该旋转到横向,那么它工作正常,但是当我们更改选项卡时,它仍然处于横向,这不是我们想要的!

总而言之,是否有人找到了一种解决方案,可以将几乎所有 View 锁定到除一个之外的给定方向,并且可以更改选项卡所在的方向(此处为纵向)?

我也读过这篇文章iOS 6 UITabBarController supported orientation with current UINavigation controller ,但正如一条评论也提到“这几乎对我有用。问题是,如果我已经处于横向状态,当我将选项卡切换到纵向时,仅查看它仍然处于横向状态。旋转纵向可以修复它,并且不会旋转回去横向,但我仍然需要它在第一次加载时处于纵向”,这在这里几乎是相同的..

最佳答案

我自己也遇到过这个问题,我找到了一个解决方案,虽然不太漂亮,但很有效。

在您的 TabbarController 子类中实现此 tabbarcontroller 委托(delegate)函数(记住设置委托(delegate)):

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    int selected = self.selectedIndex;
    UIViewController *con = [[UIViewController alloc] initWithNibName:@"XIBName" bundle:nil];
    [[self.viewControllers objectAtIndex:selected] pushViewController:con animated:NO];
    [[self.viewControllers objectAtIndex:selected]popViewControllerAnimated:NO];
    [[self.viewControllers objectAtIndex:selected] setDelegate:nil];
}

选项卡导航 Controller 中的 uinavigationcontroller 上的推送和弹出将使 tabbarcontroller 再次触发其方向功能,如果您正确实现了方向代码,它将更改为您想要的方向。

我希望这有帮助,如果我需要详细解释任何内容,请随时发表评论。

致以诚挚的问候 莫滕

关于ios - 带有导航 Controller 方向的标签栏 Controller ios 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13622194/

相关文章:

ios - 支持 Retina 4 英寸,部署目标为 4.3

ios - 在 ios Objective-c 的 mapview 上添加带有多个图像的多个注释?

ios - Objective-C 中的委托(delegate)级联和劫持委托(delegate)回调

ios - 当您从不同的 View Controller 转入时,如何将数据从一个 View Controller 保存(附加)到另一个 View Controller ?

ios - 使用 UITabBar 和 UINavigationBar

iOS:在旧 iOS SDK 中使用新 SDK 中的常量

ios - 无法在混合 View 或卫星 View 上倾斜 MKMapkit map

iphone - 在 Objective-c 中编码二维数组

ios - UINavigationController navBar 内的 UIPageViewController 中的 UITableViewController 不反弹

ios - 无法更改状态栏样式