0

Screenshot

Hi... I am having an app in which I am using UIAlerController to show alert view.

I am sucessfully able to show it but the problem is I can not dismiss the view on touching outside. I have to create a view manually and a cancel button (shown in screenshot).

I know I can get the touch with putting Uialertactionstyle cancel but that makes my UI improper.

So Is there any other way so that I can get the touch event on outside touch?

Thanks in advance.

Manthan
  • 3,856
  • 1
  • 27
  • 58
  • Refer this - Add the gesture as you want and dismiss the alert -https://stackoverflow.com/questions/4660371/how-to-add-a-touch-event-to-a-uiview – Suresh Thayu Sep 25 '17 at 06:33
  • Thanks for your reply. I tried this but gesture only works for that view having white background. It doesn’t give outside touch which I have specified. – Manthan Sep 25 '17 at 06:36
  • Add gesture to view first, then `[self.view endEditing:YES];` – Otis Lee Sep 25 '17 at 07:02

1 Answers1

0

I try to use xcode tool to see the view hierarchy ,and it looks like as below:

enter image description here

I find the correct view to add tap gesture,so I modify the code and it works.

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);
}
ColeX
  • 14,062
  • 5
  • 43
  • 240