UITabBarController + UINavigationController和更多选项卡黑屏问题 [英] UITabBarController + UINavigationController and more tab black screen issue

查看:71
本文介绍了UITabBarController + UINavigationController和更多选项卡黑屏问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在对我的一个应用程序进行更新,我遇到了一个与UITabBarController有关的非常奇怪的问题.

I'm currently working on an update to one of my apps and I have come across a very strange issue to do with UITabBarController.

在我的情节提要中,我有大约8个视图控制器,在UITabBarController子类中,我添加了另外4个以编程方式加载的视图控制器.这些视图中的大多数都需要UINavigationController来保持旋转时的一致性,因为某些视图从更多"选项卡进入主栏中时,为了做到这一点,我将它们嵌入了UINavigationController中.

In my storyboard I have about 8 view controllers and in my UITabBarController subclass I add another 4 view controllers that are loaded programmatically. Most of these views need to have to UINavigationController to keep consistency when rotating as some views come out from the "More" tab into the main bar, in order to do this I have embeded them in a UINavigationController.

如果您选择纵向6视图并在视图在选项卡栏中获得其自己的按钮时,UINavigationController旋转为黑色,但是当视图返回更多"时,视图将返回.在我对这些问题的调查中,似乎UINavigationController失去了UIViewController作为其根视图控制器.

If you choose view 6 in portrait and the rotate the UINavigationController goes black when the view gets its own button in the tab bar, however when it returns to "more" the view comes back. In my investigation of these it seems that the UINavigationController losses the UIViewController as it root view controller.

在未进入更多"标签的视图上按预期工作:imgur.com/gVB8wTF

Working as expected on a view that does not enter the "More" tab: imgur.com/gVB8wTF

黑屏(如果视图来自更多"标签): http://imgur.com/WaoNoL1

Black screen if the view came from the "More" tab: http://imgur.com/WaoNoL1

我制作了一个具有以下问题的快速示例项目: https://github.com/joshluongo/UITabBarController -问题

I made a quick sample project that has this issue: https://github.com/joshluongo/UITabBarController-Issues

关于如何解决此问题的任何想法?

Any ideas on how to fix this?

推荐答案

我发现了一种可以解决此问题的解决方法.

I have found a workaround that seems to get around this issue.

通过覆盖UITabBarController子类中的UITraitCollection,可以强制horizontalSizeClass始终为UIUserInterfaceSizeClassCompact.这将使UITabBar仅具有5个项目,而与方向无关.

By overriding the UITraitCollection in a UITabBarController subclass you can force the horizontalSizeClass to always be UIUserInterfaceSizeClassCompact. This will make the UITabBar only ever have 5 items regardless of the orientation.

这里有一些示例Objective-C代码:

Here some sample Objective-C code:

- (UITraitCollection *)traitCollection {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        // Workaround to fix the iPhone 6 Plus roatation issue.
        UITraitCollection *curr = [super traitCollection];
        UITraitCollection *compact = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];

        return [UITraitCollection traitCollectionWithTraitsFromCollections:@[curr, compact]];
    }

    return [super traitCollection];
}

然后,如果需要访问真实特征,则在UIViewController中覆盖-traitCollection以从[UIScreen mainScreen]返回特征.

Then if you need access to real traits then override -traitCollection in your UIViewController to return the traits from [UIScreen mainScreen].

下面是一些示例性的Objective-C代码:

Here some example Objective-C code to do that:

- (UITraitCollection *)traitCollection {
    return [UIScreen mainScreen].traitCollection;
}

这不是理想的解决方案,但是在Apple决定修复此错误之前,这将完成工作.

This not an ideal solution but until Apple decides to fix this bug, this will do the job.

我希望这对某人有帮助.

I hope this helps someone.

rdar://21297168

rdar://21297168

这篇关于UITabBarController + UINavigationController和更多选项卡黑屏问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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