Skip to content
This repository

UINavigationController in master view controller resize problems #35

Open
ghost opened this Issue · 3 comments

3 participants

Steven E Wright Andrew Roberts Evan D. Schoenberg, M.D.
Deleted user
ghost commented

I am using MGSplitViewController with properties:

self.splitViewController.showsMasterInPortrait = YES;
self.splitViewController.splitPosition = 300;

I have a UINavigationController set to the masterViewController property, and upon rotating from lanscape to portriate, the navigation items are squished. I get around this at the moment with the following code within my master view controller:

  • (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { // MGSplitViewController seems to incorrectly resize the master vc's navbar items upon // rotating from landscape to portriate. We explicitely resize them here. [self.navigationItem.titleView sizeToFit]; UIButton *doneButton = (UIButton *)self.navigationItem.leftBarButtonItem.customView; [doneButton sizeToFit]; }
Steven E Wright

+1 Same Issue

I wasn't able to fix the issue with the same workaround reakinator used. I'm sure my situation is different... so, for anyone else struggling with this - the only way I was able to get around the problem was to remove the leftBarButtonItem prior to rotation, and add it back in afterwards:

@property (nonatomic, retain) IBOutlet UINavigationBar * header;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *editButton;

....

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    self.header.topItem.leftBarButtonItem = nil;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    self.header.topItem.leftBarButtonItem = self.editButton;
}
Andrew Roberts

I'm experiencing a similar bug when I put a UISegmentedControl into the master's navigation bar. Everything launches looking fine, but give it a rotation and suddenly the segemented control width shrinks to only a few pixels, and the labels are spilling out.

The work-around I found was similar to what reakinator mentioned and is to rectify things in the didRotateFromInterfaceOrientation method. In my case I reset the segment control's frame width. It's a big ugly though because you do notice the control being redrawn to fit its specified size.

Evan D. Schoenberg, M.D.

I found a work-around without the visual glitch of the control disappearing and reapparing.
In -[MGSplitViewController willAnimateRotationToInterfaceOrientation:duration:], move the calls to the master and detail view controllers to happen after the relayout call:

--- a/Classes/MGSplitViewController.m
+++ b/Classes/MGSplitViewController.m
@@ -186,9 +186,6 @@
 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                                                                 duration:(NSTimeInterval)duration
 {
-       [self.masterViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
-       [self.detailViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
-       
        // Hide popover.
        if (_hiddenPopoverController && _hiddenPopoverController.popoverVisible) {
                [_hiddenPopoverController dismissPopoverAnimated:NO];
@@ -197,6 +194,9 @@
        // Re-tile views.
        _reconfigurePopup = YES;
        [self layoutSubviewsForInterfaceOrientation:toInterfaceOrientation withAnimation:YES];
+       
+       [self.masterViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
+       [self.detailViewController willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
 }

Then, in your master view controller, resize your UIBarButtonItems:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    /* When MGSplitViewController rotates, it causes a resize of our view; we need to resize our UIBarButtonControls or they will be 0-width */
    [self updateBarButtonIems];

    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.