gpt4 book ai didi

ios - UIAlertController 上的 UITapGestureRecognizer 未触发

转载 作者:行者123 更新时间:2023-11-29 05:39:24 26 4
gpt4 key购买 nike

我试图将 UITapGestureRecognizer 附加到 UIAlertController 的 View ,但识别事件永远不会触发。

我正在 Xamarin 中进行编码,但我觉得这个问题也适用于 native 代码。

InvokeOnMainThread(() =>

var alert = new UIAlertController();
alert.Title = "My Title";
alert.Message = "My Message";

UITapGestureRecognizer tapGestureRecognizer = new
UITapGestureRecognizer((gesture) =>
{
//I never get here
});

alert.View.AddGestureRecognizer(tapGestureRecognizer);
alert.View.UserInteractionEnabled = true;

this.PresentViewController(alert, true, null);
});

理想情况下,我想在用户触摸弹出窗口时关闭警报,但我似乎无法检测到该手势。

我尝试在警报出现之前和之后添加识别器。

最佳答案

解决方案:

驳回UIAlertController通过单击背景 View ,您可以添加 tapGestureRecognizer UIAlertController 时到屏幕中的最后一个 View 弹出,检查下面的代码:

public partial class ViewController : UIViewController
{
public ViewController (IntPtr handle) : base (handle)
{
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.

var alert = new UIAlertController();
alert.Title = "My Title";
alert.Message = "My Message";

UIAlertAction ac1 = UIAlertAction.Create("123",UIAlertActionStyle.Cancel,null);

alert.AddAction(ac1);

this.PresentViewController(alert, true, addGesOnBackGround);
}

public void addGesOnBackGround() {

UIView backView = new UIView();

Array arrayViews = UIApplication.SharedApplication.KeyWindow.Subviews;

if (arrayViews.Length >0)
{
backView = arrayViews.GetValue(arrayViews.Length-1) as UIView;
}

UITapGestureRecognizer tapGestureRecognizer = new
UITapGestureRecognizer((gesture) =>
{
//I never get here
this.DismissViewControllerAsync(true);

});

backView.AddGestureRecognizer(tapGestureRecognizer);
backView.UserInteractionEnabled = true;
}

}

关于ios - UIAlertController 上的 UITapGestureRecognizer 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56705588/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com