Xamarin.ios 如何在Xamarin iOS(iPhone)中创建popover?

Xamarin.ios 如何在Xamarin iOS(iPhone)中创建popover?,xamarin.ios,Xamarin.ios,我正在创建一个页面,点击一个按钮,弹出框就会出现在所附的屏幕截图中。 我几乎尝试了很多方法来实现这一点,但最终都是全屏显示。真的没有办法在Xamarin iOS中创建popover吗 有人能帮我吗?您可以构建自定义的pop视图控制器,然后将其与Popover一起呈现: //The pop view controller you want to show, here I use Storyboard to initialize it PopoverViewController popViewCon

我正在创建一个页面,点击一个按钮,弹出框就会出现在所附的屏幕截图中。 我几乎尝试了很多方法来实现这一点,但最终都是全屏显示。真的没有办法在Xamarin iOS中创建popover吗


有人能帮我吗?

您可以构建自定义的pop视图控制器,然后将其与
Popover一起呈现:

//The pop view controller you want to show, here I use Storyboard to initialize it
PopoverViewController popViewController = Storyboard.InstantiateViewController("PopoverViewController") as PopoverViewController;

//Set the presentation style to popover
popViewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
//The popover view's size
popViewController.PreferredContentSize = new CGSize(150, 150);

//The pop view's position
popViewController.PopoverPresentationController.SourceView = MyBtn;
popViewController.PopoverPresentationController.SourceRect = MyBtn.Bounds;
popViewController.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Up;
//We can also customize the background color
//popViewController.PopoverPresentationController.BackgroundColor = UIColor.White;

popViewController.PopoverPresentationController.Delegate = new PopOverViewDelegate();
PresentModalViewController(popViewController, true);
不要忘记设置下面的委托以在iPhone上实现相同的效果:

public class PopOverViewDelegate : UIPopoverPresentationControllerDelegate
{
    public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
    {
        return UIModalPresentationStyle.None;
    }
}

您可以构造自定义pop视图控制器,然后将其与
Popover
一起呈现:

//The pop view controller you want to show, here I use Storyboard to initialize it
PopoverViewController popViewController = Storyboard.InstantiateViewController("PopoverViewController") as PopoverViewController;

//Set the presentation style to popover
popViewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
//The popover view's size
popViewController.PreferredContentSize = new CGSize(150, 150);

//The pop view's position
popViewController.PopoverPresentationController.SourceView = MyBtn;
popViewController.PopoverPresentationController.SourceRect = MyBtn.Bounds;
popViewController.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Up;
//We can also customize the background color
//popViewController.PopoverPresentationController.BackgroundColor = UIColor.White;

popViewController.PopoverPresentationController.Delegate = new PopOverViewDelegate();
PresentModalViewController(popViewController, true);
不要忘记设置下面的委托以在iPhone上实现相同的效果:

public class PopOverViewDelegate : UIPopoverPresentationControllerDelegate
{
    public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
    {
        return UIModalPresentationStyle.None;
    }
}

谢谢你的回复。但它对我不起作用。点击按钮没有任何动作。@BBB我为你制作了一个样本。谢谢你的回复。但它对我不起作用。点击按钮没有任何动作。@BBB我为你制作了一个样本。