Xamarin - iOS:UIActionSheet忽略了外面的点击

时间:2014-08-28 08:54:23

标签: ios xamarin uiactionsheet uitapgesturerecognizer

我阅读了以下文章并尝试了它,但它不能工作:

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

我有一个Menu-Class(来自uiactionsheet的超类)并在其中注册了TapRecognizer。当UIActionSheet可见并且点击它(不在外面)时,它会执行Taprecognizer。但是在外面的水龙头上,没有任何事情发生。

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();
        }
    }

}

以下代码初始化菜单并显示它。

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

谁能告诉我出了什么问题?感谢。

0 个答案:

没有答案