I am using this custom component to show messages on iOS (kinda like a toast in android).
In android the toast is always rendered on top, but on iOS, if a popUP is open, the message is rendered behind the layout:
void ShowAlert(string message, double seconds)
{
Device.BeginInvokeOnMainThread(() => {
alertDelay = NSTimer.CreateScheduledTimer(seconds, (obj) =>
{
dismissMessage();
});
alert = UIAlertController.Create("", message, UIAlertControllerStyle.Alert);
var window = UIApplication.SharedApplication.Delegate.GetWindow();
window.RootViewController.PresentViewController(alert, true, null);
});
}
How can I set the z axis of a view so that it will be page -> popup -> message.
Thank you
Try to achieve it by creating a custom "popup" UIView.
Just define a custom UIView to show the "Alert", then the toast will shown topmost.
MyPopupView class:
class MyPopupView : UIView
{
public MyPopupView(string message, string buttonText)
{
this.Frame = new CGRect(50, UIScreen.MainScreen.Bounds.Height / 2 - 30, UIScreen.MainScreen.Bounds.Width - 100, 80);
this.Layer.CornerRadius = 8;
this.BackgroundColor = UIColor.FromRGB(230, 230, 230);
UILabel label_Message = new UILabel();
label_Message.Text = message;
label_Message.Frame = new CGRect(20, 10, 200, 20);
UIButton button_OK = new UIButton();
button_OK.SetTitle(buttonText, UIControlState.Normal);
button_OK.SetTitleColor(UIColor.Red, UIControlState.Normal);
button_OK.Frame = new CGRect(this.Bounds.Width / 2 - 30, this.Bounds.Height / 2 + 10, 60, 20);
button_OK.TouchUpInside += Button_OK_TouchUpInside;
this.AddSubview(label_Message);
this.AddSubview(button_OK);
}
private void Button_OK_TouchUpInside(object sender, EventArgs e)
{
this.RemoveFromSuperview();
}
}
Add MyPopupView:
MyPopupView myPopupView = new MyPopupView("A message here!", "I know");
this.View.AddSubview(myPopupView);
FWIW, In my test I used Toast.iOS .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.