我无法使用UIPopoverPresentationController
呈现一个Popover,我可以在互联网上找到,包括this和this。没有任何帮助。这是我创建的测试应用程序:
ViewController.cs
public override void ViewDidLoad()
{
...
var popupView = new UIImageView(new CGRect(0, 0, 200, 200))
{
Image = UIImage.FromBundle("Menu")
};
_menuController = new UIViewController
{
ModalPresentationStyle = UIModalPresentationStyle.Popover,
View = popupView
};
_presentationController = new UIPopoverPresentationController(_menuController, this)
{
SourceView = View,
SourceRect = new CGRect(50, 50, 300, 300),
};
}
我按下按钮按下:
PresentViewController(_menuController, true, null);
当演示文稿样式为Popover
时,我收到此异常:
UIPopoverPresentationController应该有一个非零的sourceView或 barButtonItem在演示文稿发生之前设置。
答案 0 :(得分:1)
每个UIViewController
都有一个名为UIPopoverPresentationController
的{{1}},你可以用它来展示你的流行视图:
PopoverPresentationController
我发现当我们关闭popoverview时,它将返回null。所以我建议你每次出现时都用你的方法初始化它。
此外,如果您想在iPhone上实现相同的效果,请添加private void OnMenuSelected(object sender, EventArgs eventArgs)
{
var popupView = new UIImageView(new CGRect(0, 0, 200, 200))
{
Image = UIImage.FromBundle("Menu"),
UserInteractionEnabled = true
};
_menuController = new UIViewController
{
ModalPresentationStyle = UIModalPresentationStyle.Popover,
PreferredContentSize = new CGSize(200, 200),
View = popupView
};
_menuController.PopoverPresentationController.SourceRect = new CGRect(50, 50, 300, 300);
_menuController.PopoverPresentationController.SourceView = View;
PresentViewController(_menuController, true, null);
}
之类的:
UIPopoverPresentationControllerDelegate
将代理设置为:public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
return UIModalPresentationStyle.None;
}
答案 1 :(得分:0)