UIPopoverPresentationController not rendering properly

391 views Asked by At

I'm attempting to display a small modal popover using the new UIPopoverPresentationController, and while it's more or less working, the popover bubble that it is contained in is being cut off in a very weird way:

enter image description here

Looks like there is a piece missing from the bottom, but I can't figure out why.

Here is the code I am using to present the popover (note that the sourceView is on an inputAccessoryView):

UIViewController *popoverVC = [self.storyboard instantiateViewControllerWithIdentifier:@"profilePopover"];
popoverVC.preferredContentSize = CGSizeMake(300,120);
popoverVC.modalPresentationStyle = UIModalPresentationPopover;
self.profilePopoverController = popoverVC.popoverPresentationController;
self.profilePopoverController.delegate = self;
self.profilePopoverController.sourceView = self.chatBar.profilePictureButton;
self.profilePopoverController.sourceRect = self.chatBar.profilePictureButton.bounds;
self.profilePopoverController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popoverVC.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:popoverVC animated:YES completion:nil];
1

There are 1 answers

0
Cory Imdieke On

I've just run into this issue when presenting my own popover from a segue, and every time I thought I fixed it, it cropped up again.

I think I've finally got it though. It seems to be related to the values in the destination controller's preferredContentSize and the popover controller's sourceRect. The content size was the one that I had to adjust the most.

If the size values aren't integral (so it needs to be 2.0 not 2.5 for example) or if they aren't even (so it can be 2.0 but not 1.0), this would happen. I've included my prepare for segue method where I set everything up. I wanted my popover size to be relational to the total size of my view, but this should apply to more than just that scenario. My button size (for the sourceRect) is fixed so my measurements happen to work without needing similar adjustment, but I'm guessing the same limitations apply here as well.

if let button = sender as? UIButton where segue.identifier == "FAQSegue" {
    let fullViewSize = self.view.bounds

    let controller = segue.destinationViewController
    let popoverController = controller.popoverPresentationController
    popoverController?.delegate = self
    var w = round(fullViewSize.width * 0.85)
    var h = round(fullViewSize.height * 0.85)
    w = (w % 2 == 0) ? w : w + 1
    h = (h % 2 == 0) ? h : h + 1
    controller.preferredContentSize = CGSize(width: w, height: h)

    // Set arrow position to middle of button
    popoverController?.sourceRect = CGRectMake(button.bounds.width / 2.0, 5.0, 0.0, 0.0)
}

I can't say for sure that these are the only triggers for this issue, but it did end up fixing it for me on all iPhone screen sizes.