ios - Xamarin-ios 在 UiAlertController 外部单击时关闭它

标签 ios xamarin xamarin.ios

我正在为 AlertView 使用第三方库。

图书馆链接在这里 -> https://github.com/kvandake/InteractiveAlert-Xamarin

当用户在 AlertView 外部单击时,我想关闭 AlertView,如何实现此目的?

我尝试了 dissmisViewController 但它不起作用。 另外,我查看了一些旧的 StackOverflow 问题并尝试使用 UITapGestureRecognizer,但它不会工作。

我的代码是这样的

 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);
            };

        }

谢谢

最佳答案

已解决

alertController.View.UserInteractionEnabled = true;
alertController.View.AddGestureRecognizer(new UITapGestureRecognizer(() => {
    alertController.HideView();
}));

关于ios - Xamarin-ios 在 UiAlertController 外部单击时关闭它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47782408/

相关文章:

c# - 在 iOS 上将自定义呈现的页面移动到状态栏下方

Xamarin Forms 图像填充宽度与适当的宽高比

ios - 无法将结构从非托管库编码为单触摸中的托管代码

iphone - 将 C# 编译成 objective-C

ios - 由于标识符错误没有 segue,无法执行 segue

ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : '-[__NSCFString size]: unrecognized selector sent to instance

ios - 使用 touchesbegan、touchesmoved 和 touchesended 不能使拖动流畅地进行动画处理

ios - 无法将字符串...转换为 Swift 中的字符串

c# - 具有绑定(bind)属性的图像 IsEnabled 不起作用 Xamarin 表单

iphone - 当设备方向改变时,自定义 UIView 不会旋转