Search code examples
rotationuitabbarcontrolleruitabbarsfsafariviewcontrolleruitraitcollection

Tab Bar Ignoring UITraitCollection requests - 6 Tabs Desired


I'm using the following code to trick my application into believing it's an iPad and displaying 6 tabs on the tab bar.

-(UITraitCollection *)traitCollection
{
    UITraitCollection
    *realTraits = [super traitCollection],
    *lieTrait = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
    return [UITraitCollection traitCollectionWithTraitsFromCollections:@[realTraits, lieTrait]];
}

This is all well and good, apart from when returning from a SFSafariViewController which I've rotated a couple of times. The issue I'm having is that the tab bar defaults back and shows four tabs along with the more page. What's my issue? It's important to note that just opening the SFSafariViewController and then going back DOESN'T trigger the Tab Bar to default - so I'm presuming it has something to do with the rotation putting a new view on top (a view which is ignoring the UITraitCollection call).

I've subclassed the SFSafariViewController and UITabBarController, while trying to call the method above when ever possible to stop the Tab Bar defaulting - however I'm having no success.

NOTE: I am getting a, '[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction' error when rotating - if that is of any help.

Thank You.


Solution

  • I ended up solving this by implementing the snippet below into my suclassed UINavigationController.

    - (UITraitCollection *)overrideTraitCollectionForChildViewController:(UIViewController *)childViewController
    {
        return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
    }
    

    Hope that helps someone else with the problem!