Power78
Power78

Reputation: 331

UISplitViewController, how to always use UISplitViewControllerDisplayModePrimaryOverlay

I'm developping an iOS app targeting iOS 8 devices and I use a UISplitViewController.

I want to use UISplitViewControllerDisplayModePrimaryOverlay as the default presentation mode for the Primary view Controller instead of UISplitViewControllerDisplayModeAllVisible.
But then, when I run the app, the UISplitViewController is already in UISplitViewControllerDisplayModePrimaryOverlay.

What I'm looking for is when I open the app, I'm in UISplitViewControllerDisplayModePrimaryHidden, but then, presenting the primary vc should be in UISplitViewControllerDisplayModePrimaryOverlay.

I use the delegate method - (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc
like this : self.splitviewcontroller.preferedDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
At instantiation of the SplitVC; and then

- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc
{
    if (svc.displayMode == UISplitViewControllerDisplayModePrimaryOverlay)
    {
        return UISplitViewControllerDisplayModePrimaryHidden;
    }
    else
    {
        return UISplitViewControllerDisplayModePrimaryOverlay;
    }
}

But it makes the constraints inside my primary vc break (but not when i'm not overriding targetDisplayModeForActionInSplitViewController:).

Does somebody has the solution to my problem :( ?
Thanks by advance.

EDIT :

I tried to override the Idiom UITrait of the SplitViewController to iPad, but it doesn't work either :(

Upvotes: 2

Views: 2772

Answers (1)

Power78
Power78

Reputation: 331

I succeeded to make it "work".

On rotation I'm forced to change the display mode to UISplitViewControllerDisplayModePrimaryHidden to avoid bugs.

I overrided willTransitionToTraitCollection inside my SplitViewController :

- (void)willTransitionToTraitCollection:(UITraitCollection *)newCollection withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
    self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
    [super willTransitionToTraitCollection:newCollection withTransitionCoordinator:coordinator];
}

and then I overrided targetDisplayModeForActionInSplitViewController in my SplitViewController Delegate :

- (UISplitViewControllerDisplayMode)targetDisplayModeForActionInSplitViewController:(UISplitViewController *)svc
{
    if (svc.displayMode == UISplitViewControllerDisplayModePrimaryHidden)
    {
        return UISplitViewControllerDisplayModePrimaryOverlay;
    }
    return UISplitViewControllerDisplayModePrimaryHidden;
}

So now I have a very cool looking Overlay :)

Upvotes: 2

Related Questions