带有导航控制器方向的Tabbar控制器ios 6 [英] Tabbar controller with navigationcontrollers orientation ios 6

查看:171
本文介绍了带有导航控制器方向的Tabbar控制器ios 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个项目,我们有一个带有4个标签的标签栏控制器,每个标签都有一个导航控制器。在每个导航控制器上都有多个视图控制器。

I'am currently working on an project where we have a tab bar controller with 4 tabs, and where each tab have an navigation controller. On each of these navigation controller there is multiple viewcontrollers pushed on it.

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

I read a lot of post here and other places, and we have currently done the following:

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

如果我们在每个viewcontrollers中指定以下内容,这项工作正常:

This work fine, if we in each of our viewcontrollers specify the following:

- (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

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

这将按预期将其锁定为Portrait。

This will lock it to Portrait as expected.

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

But now the real problem occurs! If we in our viewcontroller on one of the tabs specify that it should rotate to landscape it works fine, but when we then change tab it is still in landscape, which is not what we want!

总而言之,有没有人能够解决你如何将几乎所有视图锁定到给定方向的方法,并且可以更改标签,使其位于您指定的方向(此处为纵向)?

So to sum up, have anyone got a solution to how you lock almost all views to a given orientation expect one, and can change tabs where they are in the orientation you specified (here portrait)?

我还阅读了这篇文章 iOS 6 UITabBarController支持使用当前UINavigation控制器的方向,但正如一条评论中也提到这几乎对我有用。问题是如果我将标签切换为纵向时已经处于横向状态只有视图它仍然在风景中。旋转的肖像修复它,它不会旋转回景观,但我仍然需要它在第一次加载时的肖像这里几乎是相同的..

I also read this post iOS 6 UITabBarController supported orientation with current UINavigation controller, but as one comment also mentioned "This is almost working for me. The problem is if I am already in landscape when I switch tabs to a portrait only view it is still in landscape. Rotating portrait fixes it and it won't rotate back to landscape, but I still need it be in portrait when it first loads" which almost is the same here..

推荐答案

我自己遇到了这个问题而且我找到了一个解决方案,它并不漂亮,但它确实有效。

I myself had this problem and i worked out a solution, its not pretty but it works.

在你的TabbarController子类中实现这个tabbarcontroller委托函数(记得设置委托):

In your TabbarController subclass implement this tabbarcontroller delegate function (remember to set 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];
}

选项卡navigationcontroller中uinavigationcontroller的推送和弹出将使tabbarcontroller触发它的Orientations再次起作用,如果你正确实现了方向代码,它将改变你想要的方向。

The push and pop on the uinavigationcontroller in the tabs navigationcontroller will make the tabbarcontroller fire its Orientations functions again, and if you implemented the orientations code correctly it will change to your desired orientation.

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

i hope this helps, please fell free to comment if i need to explain anything in details.

最好的问候
Morten

Best Regards Morten

这篇关于带有导航控制器方向的Tabbar控制器ios 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆