2017-09-25 71 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); 
} 
相關問題