Xamarin IOS:如何通过按钮单击显示弹出控件

Bob*_*Bob 4 c# ios xamarin

这适用于iPhone.

我有一个按钮,当它被点击时,我想弹出另一个覆盖整个屏幕的控件.此屏幕可以有任意数量的控件.我可以通过单击右上角的x或以编程方式在新屏幕上的任何事件内关闭此屏幕.

我可以通过使用UINavigationController来做到这一点,它只是带我到一个新的屏幕,并有一个链接回到上一个屏幕,但我只想问是否有另一个选项?

我正在做的是我有一张地图,显示一个用户的位置.但是,如果用户想要输入新位置而不是使用引脚位置,那么他们将单击按钮,转到新屏幕,键入地址并从他们键入的内容中单击"建议"地址.

任何建议都会受到赞赏,或者代码示例的链接会很棒

Jas*_*son 8

如果它是iPad应用程序,您可以使用UIPopoverController.

// myvc is an instance of the view controller you want to display in the popup
UIPopoverController pop = new UIPopoverController(myvc);

// target is another view that the popover will be "anchored" to
pop.PresentFromRect(target.Bounds, target, UIPopoverArrowDirection.Any, true);
Run Code Online (Sandbox Code Playgroud)

如果是iPhone应用程序,则无法使用UIPopoverController.如果你只想要一个带有单个按钮的小输入框,你可以使用UIAlertView(适用于iPhone和iPad)

UIAlertView alert = new UIAlertView();
alert.Title = "Title";
alert.AddButton("OK");
alert.Message = "Please Enter a Value.";
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alert.Clicked += (object s, UIButtonEventArgs ev) => {
  // handle click event here
  // user input will be in alert.GetTextField(0).Text;
};

alert.Show();
Run Code Online (Sandbox Code Playgroud)


Ric*_*omo 8

你不能在iPhone上使用popover,我认为你可以使用Modal View.

yourButton.TouchUpInside += (object sender, EventArgs e) => 
{
    YourController yourController = new YourController();

    yourController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
    this.PresentViewController(yourController, true, null);
};
Run Code Online (Sandbox Code Playgroud)

关闭你只需要解雇模态.