[英]Xamarin-ios Dismiss UiAlertController when clicking outside of it
I'm using third party library for AlertView. 我正在使用第三方库的AlertView。
Library is linked here -> https://github.com/kvandake/InteractiveAlert-Xamarin 库在这里链接-> https://github.com/kvandake/InteractiveAlert-Xamarin
I want to dismiss AlertView when the user clicks outside of it, how I can achieve this? 我想在用户单击外部的AlertView时将其关闭,我该如何实现?
I tried dissmisViewController but it won't work. 我尝试了dissmisViewController,但无法正常工作。 Also, I looked some old StackOverflow questions and tried to do it with UITapGestureRecognizer, but it won't work.
另外,我查看了一些旧的StackOverflow问题,并尝试使用UITapGestureRecognizer进行此操作,但是它不起作用。
My code looks like this 我的代码看起来像这样
barItem.Clicked += delegate
{
InteractiveAlertView alertController = new InteractiveAlertView();
var text = alertController
.AddTextField("MyAltfolio");
var button = alertController.AddButton("Add", async () =>
{
string value = text.Text;
var db = DatabaseManager.Instance;
var altfolio = await db.InsertAltfolioAsync(value);
}, Theme.TintColor, Theme.TextColor);
alertController
.ShowCustom("Altfolios", "Enter name for your altfolio", Theme
.TintColor, getImageWithColor(Theme.TextColor, UIImage
.FromBundle("albums.png")), "Submit", 0, UIColor
.Red, UIColor
.Purple);
};
}
Thank you 谢谢
SOLVED 解决了
alertController.View.UserInteractionEnabled = true;
alertController.View.AddGestureRecognizer(new UITapGestureRecognizer(() => {
alertController.HideView();
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.