2

I am using auto layout with Storyboard. I present a popoverPresentationController from a cell rect:

NumberController * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NumberController"];
UIPopoverPresentationController *pc = [viewController popoverPresentationController];
    pc.delegate = self;
    pc.permittedArrowDirections = UIPopoverArrowDirectionAny;
    pc.sourceView = tableView;
    pc.sourceRect = [tableView rectForRowAtIndexPath:indexPath];
    [self.navigationController presentViewController:viewController animated:animated completion:nil];

The popover presents on an iPad in portrait mode with the arrow up.

I rotate the iPad to landscape mode. The popoverPresentationController keeps the same sourceView/sourceRect and properly points to the cell. It also keeps the up arrow.

But it is now at the bottom of the view, so the popover resizes to a shorter height. This is not desired behavior.

If the popover were simply to move to a new position and change the arrow direction, it would not need to resize at all. This is the desired behavior.

I thought the following method might permit me to make changes, but it is not called since the sourceView rect does not change:

- (void)popoverController:(UIPopoverController *)popoverController
willRepositionPopoverToRect:(inout CGRect *)rect
                   inView:(inout UIView **)view {

}

I have tried to reset the permittedArrowDirections (in preferredContentSize, because this seemed like the most logical place). This does not work (the popover still resizes):

- (CGSize) preferredContentSize {
    [super preferredContentSize];
    self.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUnknown;
    return CGSizeMake(DEFAULT_POPOVER_WIDTH,DEFAULT_POPOVER_HEIGHT);
}

I simply cannot find a way to force the popoverPresentationController to change arrow direction and reposition the popover instead of resizing the popover. I am beginning to think it is not even possible - but I still hold out hope that I am just missing something.

EDIT: In the meantime, it has occurred to me that maybe a popover is not the best way to present this view if I don't want it resized in iPad. I am going to try it with UIModalPresentationFormSheet presentation. But I would still like to find an answer to this question.

SAHM
  • 4,078
  • 7
  • 41
  • 77

1 Answers1

2

I just ran into the problem where

    - (void)popoverController:(UIPopoverController *)popoverController
    willRepositionPopoverToRect:(inout CGRect *)rect
               inView:(inout UIView **)view {

was not being called because my view controller was detached. There may be a view in your view hierarchy whose view controller has not been added as a child view controller.

I thought the following method might permit me to make changes, but it is not called since the sourceView rect does not change

The sourceView rect does not have to change, just the interface orientation. From the UIPopoverControllerDelegate documentation:

For popovers that were presented using the presentPopoverFromRect:inView:permittedArrowDirections:animated: method, the popover controller calls this method when the interface orientation changes.

PastryPup
  • 166
  • 1
  • 8