【问题标题】:Popovers and Xamarin iOS弹出框和 Xamarin iOS
【发布时间】:2016-05-09 14:33:07
【问题描述】:

我在使用 Popover 的 Xamarin iOS 实现时遇到问题。

就我现在而言,它们可以通过 Apple 文档 (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPopoverPresentationController_class/) 中描述的新 UIPopoverPresentationController 类获得

我的代码是这样的:

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);          

结果有效,但我得到的是全屏视图控制器,而不是“弹出框”组件!

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

【问题讨论】:

  • 您是在 iPad 还是 iPhone 上尝试这个?看看这个:stackoverflow.com/questions/25319179/…
  • 是的,但该解决方案包括 .NET 中不支持的多重继承(来自 UIViewController 和 UIPopoverPresentationControllerDelegate)
  • 要绕过这个限制,您可以实现 IUIPopoverControllerDelegate 并重写适当的委托方法。 developer.xamarin.com/api/type/…
  • 即使尝试实现 IUIPopoverPresentationControllerDelegate 它也不起作用。我可能感兴趣的每个属性都是“只读”的,如果我设置 Controller.PopoverPresentationController.Delegate = this,则该事件不是触发事件
  • 上面第二个代码块中的“导航”是什么?

标签: xamarin.ios modal-dialog uipopovercontroller uipopover


【解决方案1】:

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

[Export("adaptivePresentationStyleForPresentationController:")]
public UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
    return UIModalPresentationStyle.None;
}

然后您必须确保将 PresentationController 的委托属性设置为您实现回调的类的引用。

pc.delegate = this;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-18
    • 1970-01-01
    相关资源
    最近更新 更多