Xamarin 在iphone和iPad的iOS中显示UIPopViewController中心
我正在使用Xamarin.iOS,我想在iphone和iPad的中央屏幕上显示UIPopViewController。下面是我尝试代码的方法:Xamarin 在iphone和iPad的iOS中显示UIPopViewController中心,xamarin,xamarin.ios,uipopovercontroller,uipopover,Xamarin,Xamarin.ios,Uipopovercontroller,Uipopover,我正在使用Xamarin.iOS,我想在iphone和iPad的中央屏幕上显示UIPopViewController。下面是我尝试代码的方法: public override void ViewDidLoad() { base.ViewDidLoad(); showButton.TouchUpInside += (sender, e) => { // Create a UIImage view to show in the popover UIImageV
public override void ViewDidLoad()
{
base.ViewDidLoad();
showButton.TouchUpInside += (sender, e) => {
// Create a UIImage view to show in the popover
UIImageView monkeyIcon = new UIImageView(new CGRect(20, 20, 200, 200));
monkeyIcon.Image = UIImage.FromFile("Abc.png");
monkeyIcon.UserInteractionEnabled = true;
// Create a view controller to act as the popover
UIViewController popover = new UIViewController();
popover.View = monkeyIcon;
popover.ModalPresentationStyle = UIModalPresentationStyle.Popover;
// Grab Image
var image = UIImage.FromFile("298-circlex.png");
// Add a close button
var closeButton = new UIButton(new CGRect(0, 20, 200, 200));
closeButton.UserInteractionEnabled = true;
closeButton.SetTitle("Close", UIControlState.Normal);
monkeyIcon.AddSubview(closeButton);
// Wireup the close button
closeButton.TouchUpInside += (button, e2) => {
popover.DismissViewController(true, null);
};
// Present the popover
PresentViewController(popover, true, null);
// Configure the popover for the iPad, the popover displays as a modal view on the
//iPhone
UIPopoverPresentationController presentationPopover = popover.PopoverPresentationController;
if (presentationPopover != null)
{
presentationPopover.SourceView = this.View;
presentationPopover.PermittedArrowDirections = 0;
presentationPopover.SourceRect = showButton.Frame;
presentationPopover.Delegate = this;
}
};
}
[Export("adaptivePresentationStyleForPresentationController:")]
public UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
return UIModalPresentationStyle.None;
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
我在SO和google上尝试了所有答案,但没有任何帮助
问题1:
-在Iphone中,PopViewController以全屏显示,但我想将PopView设置为中心和小型
问题2:
-在Ipad中,PopViewController显示在左侧,我想显示在中间
任何帮助都将不胜感激。如果您不希望此
PopoverPresentationController
全屏显示,您应该为其所有者控制器设置一个大小:popover.PreferredContentSize=new CGSize(200,200)代码>。此外,在演示popover
之前,您应该首先设置popoperpresentationcontroller
的配置
在Ipad中,PopViewController显示在我想显示的左侧
显示it中心
SourceRect
表示指定视图中用于锚定popover的矩形。如果要在中间显示此弹出窗口,请将其设置为View.Frame。以下是我的代码供您参考:
UIPopoverPresentationController presentationPopover = popover.PopoverPresentationController;
if (presentationPopover != null)
{
presentationPopover.SourceView = this.View;
presentationPopover.PermittedArrowDirections = 0;
presentationPopover.SourceRect = View.Frame;
//Configure this Delegate first before presenting.
presentationPopover.Delegate = this;
}
PresentViewController(popover, true, null);
嗨,它解决了你的问题吗?