Forum Xamarin.iOS

Preventing Popovers from going full screen for iPhone?

jpersonjperson USMember
edited June 2017 in Xamarin.iOS

I am porting a UI built initially in XCode and can't find a Xamarin way of doing the same thing.

The default behavior for "Present as Popover" segues in iOS is to show the popover on iPads and show them as full screen modals on iPhones.

In Xcode I have code in my ViewController that prevents the popover from showing as full screen on iPhones. So, I get the same behavior for "Present as Popover" for iPhones as I do for iPads.

Here is the Swift 3 code:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showPopoverMenu" {
        let popoverViewController = segue.destination

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.none

Within Xamarin I cannot get the "PrepareForSegue" to hit.

I also tried "PrepareForPopoverPresentation" to change the "PresentationStyle" but it is read-only.

Any ideas on what I am missing?


  • LukasalberLukasalber USMember ✭✭

    Ted Rogers Post worked for me.

    @TedRogers said:
    Here is some code I use to display a dropdown when a button is long-pressed:

    var popupNavVC = new PopupNavigationController(NavigationController);
    popupNavVC.PreferredContentSize = new CGSize(250f, PopupNavigationController.GetHeight(NavigationController));
    popupNavVC.ModalPresentationStyle = UIModalPresentationStyle.Popover;
    var popPresenter = popupNavVC.PopoverPresentationController;
    popPresenter.SourceView = NavigationController.NavigationBar;
    popPresenter.SourceRect = new CGRect(30, NavigationController.NavigationBar.Frame.Height-5, 0, 0);
    popPresenter.Delegate = new PopoverDelegate();
    popPresenter.PermittedArrowDirections = UIPopoverArrowDirection.Up;
    popPresenter.BackgroundColor = UIColor.White;
    PresentViewController(popupNavVC, true, null);

    The PopupNavigationController is just a view controller with a table view in it so replace with whatever you want to display. Also, use whatever you want for SourceView and SourceRect or use BarButtonItem for location of popover.

    As I remember, the PopoverDelegate was key:

    public class PopoverDelegate : UIPopoverPresentationControllerDelegate
      public PopoverDelegate()
      protected override void Dispose(bool disposing)
          Console.WriteLine(this.Class.Name + " disposed");
      public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
          return UIModalPresentationStyle.None;
      public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController controller, UITraitCollection traitCollection)
          return UIModalPresentationStyle.None;
Sign In or Register to comment.