Xamarin.ios 爆米花和Xamarin iOS

Xamarin.ios 爆米花和Xamarin iOS,xamarin.ios,modal-dialog,uipopovercontroller,uipopover,Xamarin.ios,Modal Dialog,Uipopovercontroller,Uipopover,我对Xamarin iOS的Popover实现有问题 据我所知,它们可以通过新的UIPopoverPresentationController类获得,如Apple文档() 我的代码是这样的: public partial class PopoverSettings : UIViewController { public PopoverSettings () //: base ("PopoverSettings", null) { } public overrid

我对Xamarin iOS的Popover实现有问题

据我所知,它们可以通过新的UIPopoverPresentationController类获得,如Apple文档()

我的代码是这样的:

public partial class PopoverSettings : UIViewController
{
    public PopoverSettings () //: base ("PopoverSettings", null)
    {
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        View.Frame = new CoreGraphics.CGRect(0,0,100,100);
        this.PreferredContentSize = new CoreGraphics.CGSize (10, 10);
        View.BackgroundColor = UIColor.Red;
    }
}
我试着从中创建它

var myPop = new PopoverSettings();
myPop.ModalInPopover = true;
myPop.ModalPresentationStyle = UIModalPresentationStyle.Popover;
var pc = (UIPopoverPresentationController)myPop.PresentationController;
pc.SourceView = navigation;
pc.SourceRect = new CGRect(0,0,100,100);
this.PresentViewController(myPop, true, null);          
结果是工作,但我得到了一个全屏视图控制器,而不是一个“Popover”组件


有人知道为什么会这样吗?谢谢

如果您在iPhone上实现此功能,框架将自动将您的PresentationStyle更改为全屏。要防止出现这种情况,必须实现IUIPopoverPresentationControllerDelegate接口回调“adaptivePresentationStyleForPresentationController”

[Export("adaptivePresentationStyleForPresentationController:")]
public UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
    return UIModalPresentationStyle.None;
}
然后必须确保将PresentationController的delegate属性设置为实现回调的类的引用

pc.delegate = this;

框架现在将调用您的回调,您可以强制它使其成为popover。

您是在iPad还是iPhone上尝试此功能?请看一看:是的,但该解决方案包括中不支持的多重继承(来自UIViewController和UIPopoverPresentationControllerDelegate)。要绕过该限制,您可以实现
IUIPOverControllerDelegate
,而只需覆盖适当的委托方法。即使尝试实现IUIPopoverPresentationControllerDelegate,它也无法工作。我可能感兴趣的每个属性都是“只读”的,如果我设置Controller.PopoverPresentationController.Delegate=this,则该事件不会触发。上面第二个代码块中的“导航”是什么?