How to make UIsplitview's popover visible in portrait mode iPad
Asked Answered
I

3

5

I would like to make popover view visible whenever user switches from landscape view to portrait view in UIsplitView of iPad. Although user can make it visible by clicking on bar button but I want this to be automated for portrait mode.

Itemized answered 2/9, 2010 at 15:52 Comment(0)
B
4

Inside " -(BOOL) shouldAutorotateToInterfaceOrientation" method, check for the device orientation.If it is portrait, then Present the popover as you do for making it visible when user clicks bar button.

All the best.

Bourgeois answered 27/9, 2010 at 12:52 Comment(3)
and this should be implemented in which view controller exactly?Reinert
detail view controller of your split view controller. All the best.Bourgeois
this method is deprectated in iOS 6. use didRotateFromInterfaceOrientation:Gasteropod
R
2

UISplitViewController sends messages to his delegate (UISplitViewControllerDelegate). You can implement this delegate methods to show the popover. You can do something like this in your "detail controller" code:

#pragma mark -
#pragma mark UISplitViewControllerDelegate implementation
- (void)splitViewController:(UISplitViewController*)svc 
     willHideViewController:(UIViewController *)aViewController 
          withBarButtonItem:(UIBarButtonItem*)barButtonItem 
       forPopoverController:(UIPopoverController*)pc
{  
    [barButtonItem setTitle:@"Your 'popover button' title"];
    self.navigationItem.leftBarButtonItem = barButtonItem;
}


- (void)splitViewController:(UISplitViewController*)svc 
     willShowViewController:(UIViewController *)aViewController 
  invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    self.navigationItem.leftBarButtonItem = nil;
}
Relax answered 25/2, 2011 at 17:33 Comment(1)
All your doing in these delegates is showing a button. The OP wanted the popover to be visible when rotating to portrait.Jurisprudent
A
1

The accepted answer (using shouldAutorotateToInterfaceOrientation) doesn't work for me. It either has rotation artifacts (in the 4.2 and 5.0 iPad simulators) or only shows at startup and never again in subsequent rotations (the 4.3 simulator). What I did instead was to create a little helper function:

- (void)showPopoverInPortrait {
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
        [self.masterPopoverController presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem
                                             permittedArrowDirections:UIPopoverArrowDirectionAny 
                                                             animated:YES];
    }
}

and call this within - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation and - (void)viewDidLoad to also handle on startup.

Arabela answered 2/12, 2011 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.