Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change contentSizeForViewInPopover on navigationController push on iOS

I have a UIPopoverController with navigationController and bunch of subviews. The size of the popover is set just before it's shown like this:

[self.myPopover setPopoverContentSize:CGSizeMake(320, 500)];

That works fine. The popover is shown with adjusted size. When another view is pushed on navigation stack the size of a popover is set again - need different height - in viewWillAppear method:

self.contentSizeForViewInPopover = CGSizeMake(320, 700);

This also works fine. When I go back to a previous view the size does not change.

I added the same call in viewWillAppear in first view but the view does not resize.

How can I manage resizing of popover when navigating between views?

like image 956
Borut Tomazin Avatar asked Mar 15 '12 10:03

Borut Tomazin


People also ask

How do I customize the navigation bar on my iOS app?

Create custom titles, prompts, and buttons in your app’s navigation bar. Use UINavigationBar to display your app’s navigational controls in a bar along the top of the iOS device’s screen.

How does the navigation controller update the navigation bar?

Each time the top-level view controller changes, the navigation controller updates the navigation bar accordingly. Specifically, the navigation controller updates the bar button items displayed in each of the three navigation bar positions: left, middle, and right. Bar button items are instances of the UIBarButtonItem class.

What is uinavigationcontroller UIViewController?

@MainActor class UINavigationController : UIViewController A navigation controller is a container view controller that manages one or more child view controllers in a navigation interface. In this type of interface, only one child view controller is visible at a time.

What happens to toolbar items when the active view controller changes?

When the active view controller changes, the navigation controller updates the toolbar items to match the new view controller, animating the new items into position when appropriate.


1 Answers

I use this hack:

- (CGSize)contentSizeForViewInPopover
{
    return CGSizeMake(320, 200);
}

- (void) forcePopoverSize 
{
    CGSize currentSetSizeForPopover = self.contentSizeForViewInPopover;
    CGSize fakeMomentarySize = CGSizeMake(currentSetSizeForPopover.width - 1.0f, 
                                          currentSetSizeForPopover.height - 1.0f);
    self.contentSizeForViewInPopover = fakeMomentarySize;
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self forcePopoverSize];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    CGSize currentSetSizeForPopover = self.contentSizeForViewInPopover;
    self.contentSizeForViewInPopover = currentSetSizeForPopover;
}
like image 67
Injectios Avatar answered Sep 30 '22 05:09

Injectios