1

I read the following article and tried it, but it won't work:

How to make a uiactionsheet dismiss when you tap outside eg above it?

I have a Menu-Class (Superclass from uiactionsheet) and register a TapRecognizer in it. When the UIActionSheet is visible and a tap on it (not outside) occurd, it executes the Taprecognizer. But on a tap outside, nothing happend.

public class MyMenu: UIActionSheet
{
    /// <summary>
    /// Constructor
    /// </summary>
    public MyMenu(UIView owner)
    {
        _owner = owner;
    }

    public override void Show()
    {
        ShowInView(_owner);

        var rec = new UITapGestureRecognizer(CheckTapOutside);
        rec.CancelsTouchesInView = false;
        this.Superview.AddGestureRecognizer(rec);

        // Add controls to it
    }

    public void Hide()
    {
        DismissWithClickedButtonIndex(0, true);
    }


    private void CheckTapOutside(UITapGestureRecognizer rec)
    {
        var p = rec.LocationInView(this);
        if (p.Y < 0)
        { 
            this.Hide();
        }
    }

}

The following code initializes the menu and shows it.

var menu = new MyMenu(View);
menu.Show();

Can anyone tell me what's going wrong? Thanks.

Community
  • 1
  • 1
Joehl
  • 3,671
  • 3
  • 25
  • 53

0 Answers0