2017-09-25 42 views
0

Screenshot 如何解雇UIAlertController在外面的感动,没有UIalertactionstyle取消嗨,你好,我有在我使用UIAlerController显示警报视图的应用的iOS

我成功地展示了它,但问题是我不能忽视触摸外面的观点。我必须手动创建一个视图和一个取消按钮(在屏幕截图中显示)。

我知道我可以将Uialertactionstyle取消,但这使得我的用户界面不正确。

那么还有什么其他方法可以让我在外部触摸中获得触摸事件吗?

在此先感谢。

+0

参见本 - 选择要添加的姿态和解除警报-https://stackoverflow.com/questions/4660371/how-to-add-a-touch-event-to-a-uiview –

+0

感谢您的回复。我试过这个,但手势只适用于有白色背景的那个视图。它没有给我指定的外部接触。 – Manthan

+0

添加手势先查看,然后'[self.view endEditing:YES];' –

回答

0

我尝试使用的Xcode工具查看视图层次,它看起来像如下:

enter image description here

我找到正确的视图来添加点触手势,让我修改的代码和它的工作原理。

UIAlertController alert; 
partial void UIButtonTouchUpInside(UIButton sender) 
{ 
    alert = UIAlertController.Create("title", "msg", UIAlertControllerStyle.ActionSheet); 
    this.PresentViewController(alert, true,() => 
    { 
     UITapGestureRecognizer tap = new UITapGestureRecognizer(tapAction); 
     alert.View.Superview.Subviews[0].AddGestureRecognizer(tap); 
    }); 
} 
void tapAction() 
{ 
    alert.DismissViewController(true, null); 
} 
相关问题