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

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

问题描述

我有一个我正在更新到 iOS 6 的 iPhone 应用程序,该应用程序存在轮换问题.我有一个带有 16 个 UINavigationCotrollersUITabBarController.大多数子视图可以纵向或横向工作,但其中一些仅纵向.在 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 以返回当前 navigationController 的选定 viewController 的 supportedInterfaceOrienations:

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 中实现这些方法:

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

对于您确实想要旋转的视图控制器:

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天全站免登陆