iOS 6 UITabBarController支持使用当前UINavigation控制器的方向 [英] iOS 6 UITabBarController supported orientation with current UINavigation controller

查看:97
本文介绍了iOS 6 UITabBarController支持使用当前UINavigation控制器的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序我正在更新到iOS 6,它有旋转问题。我有一个 UITabBarController ,其中包含16 UINavigationCotrollers 。大多数子视图可以在纵向或横向上工作,但其中一些只是纵向。对于iOS 6,它们不会旋转。

I have an iPhone app I am updating to iOS 6 that is having rotation issues. I have a UITabBarController with 16 UINavigationCotrollers. Most of the subviews can work in portrait or landscape but some of them are portrait only. With iOS 6 things are rotating when they shouldn't.

我尝试将tabBarController子类化以返回 supportedInterfaceOrienations 当前navigationController的选定viewController:

I tried subclassing the tabBarController to return the supportedInterfaceOrienations of the current navigationController's selected viewController:

- (NSUInteger)supportedInterfaceOrientations{

    UINavigationController *navController = (UINavigationController *)self.selectedViewController;
    return [navController.visibleViewController supportedInterfaceOrientations];
}

这让我更接近。视图控制器在可见时不会旋转到位置,但是如果我处于横向和切换选项卡中,即使不支持,新选项卡也将处于横向状态。

This got me closer. The view controller won't rotate out of position when visible, but if I am in landscape and switch tabs the new tab will be in landscape even if it isn't supported.

理想情况下,应用程序仅在当前可见视图控制器支持的方向上。有什么想法?

Ideally the app will only be in the supported orienation of the current visible view controller. Any ideas?

推荐答案

将您的 UITabBarController 子类化为覆盖这些方法:

Subclass your UITabBarController overriding these methods:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

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

-(BOOL)shouldAutorotate
{
    return YES;
}

您的 UINavigationController 的子类重写这些方法:

Subclass your UINavigationController overriding these methods:

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

-(BOOL)shouldAutorotate
{
    return YES;
}

然后在你不想旋转的viewControllers中实现这些方法: / p>

Then implement these methods in your viewControllers that you do not want to rotate:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

对于你想要旋转的viewControllers:

And for viewControllers that you do want to rotate:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }

    -(BOOL)shouldAutorotate
    {
        return YES;
    }

你的tabbarController应该被添加为应用程序窗口的RootviewController。如果您打算支持默认方向,除iPhone上的所有内容都是默认方向,那么您无需执行任何其他操作。如果您想要支持颠倒或者如果您不想支持其他方向,则需要在app delegate和/或info.plist中设置适当的值。

Your tabbarController should be added as the RootviewController of the app window. If you plan to support the default orientations, all but upsidedown is default for iPhone, then you do not need to do anything else. If you want to support upside-down or if you do not want to support another of the orientations, then you need to set the appropriate values in app delegate and/or info.plist.

这篇关于iOS 6 UITabBarController支持使用当前UINavigation控制器的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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