0

我不知道为什么我的 UIMenuController 没有出现在我的视图中。当我长按按钮时,我可以看到所有指令都已执行,但没有显示菜单。

public class MySingleArticleView : UIView
{
    private MyArticleViewController _controller; // MyArticleViewController extends BaseViewController

    public MySingleArticleView (MyArticleViewController controller, ...)
    {
        _controller = controller;

        // ... init code
    }

    void ArticleLongPressed (UILongPressGestureRecognizer gestureRecognizer)
    {
        var menuController = UIMenuController.SharedMenuController;
        var copyMenuItem = new UIMenuItem ("copy", new Selector ("CopyRow"));
        var pasteMenuItem = new UIMenuItem ("paste", new Selector ("PasteRow"));
        var location = gestureRecognizer.LocationInView (_controller.View);
        _controller.BecomeFirstResponder ();
        menuController.MenuItems = new [] { copyMenuItem, pasteMenuItem };
        menuController.SetTargetRect (new CGRect (location.X, location.Y, 0, 0), _controller.View);
        menuController.SetMenuVisible (true, true);
    }

    [Export("CopyRow")]
    void Row (UIMenuController controller)
    {
        // do something
    }

    [Export("PasteRow")]
    void PasteRow (UIMenuController controller)
    {
        // do something
    }
}

我忘记了什么?

4

2 回答 2

0

可能是因为您在设置目标矩形时提供了等于 0 的高度和宽度值:

menuController.SetTargetRect (new CGRect (location.X, location.Y, 0, 0), _controller.View);

尝试给它一个高度和宽度,看看它是否出现:

menuController.SetTargetRect (new CGRect (location.X, location.Y, 100, 100), _controller.View);
于 2015-07-13T19:12:17.570 回答
0

我自己找到了答案,也许其他人也有同样的问题。

我需要在导出的函数名之后加上冒号':',所以:

[Export("PasteRow:")] 
void PasteRow (UIMenuController controller) 
{ 

}

[Export("CopyRow:")] 
void CopyRow (UIMenuController controller) 
{ 

}

同样,在实例化时:

var copyMenuItem = new UIMenuItem ("copy", new Selector ("CopyRow:")); 
var pasteMenuItem = new UIMenuItem ("paste", new Selector ("PasteRow:"));
于 2019-06-06T07:32:46.900 回答