Home > Back-end >  Why popover does not have an arrow on iPhone?
Why popover does not have an arrow on iPhone?

Time:09-16

I am displaying a popover on a button press. Popover points its arrow to the button pressed:

UIViewController * controller = [self.storyboard instantiateViewControllerWithIdentifier: @"popover view"];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.popoverPresentationController.sourceView = button.imageView;

[self presentViewController: controller
                   animated: YES
                 completion: nil];

This is how popover view controller is defined in a storyboard: enter image description here

The problem is that on iPhone this popover is drawn fullscreen, while on iPad and Mac it is drawn with an arrow pointing to the button. I want it to have an arrow always.

I have seen that popovers on iPhone can have arrows, but cannot get it. What am I missing? Why iPhone popover is drawn fullscreen and without an arrow?

CodePudding user response:

You need to implement adaptivePresentationStyleForPresentationController:traitCollection: of UIPopoverPresentationControllerDelegate and return UIModalPresentationNone for popoverPresentationController delegate

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
                                                               traitCollection:(UITraitCollection *)traitCollection
{
    return UIModalPresentationNone;
}
  • Related