当您添加多个自定义菜单项时,显然曾经有一种简单的方法可以防止“更多...”标签出现在 UIMenuController 中。您只需删除所有系统菜单项。这里甚至还有一个解决方法,仍然可以进行复制工作。您只需使用不同的选择器实现自定义复制命令,然后覆盖 canPerformAction:withSender: 以不显示系统副本:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
return NO;
else
// logic to show or hide other things
}
不幸的是,这种方法不再有效(至少在 UIWebView 子类中)。canPerformAction:withSender: 为除了 copy: 之外的每个系统菜单项调用,因此结果是始终显示系统复制菜单项。这意味着如果您有多个自定义菜单项,它们总是隐藏在“更多...”后面
那么,有没有办法真正删除系统的复制项或其他方法来防止菜单项隐藏在“更多...”后面?
更新
这是我在覆盖 canPerformAction:withSender: 时得到的输出:请注意,从不为“copy:”操作调用该方法:
cannot perform action cut: with sender <UIMenuController: 0x7227d30>.
cannot perform action select: with sender <UIMenuController: 0x7227d30>.
cannot perform action selectAll: with sender <UIMenuController: 0x7227d30>.
cannot perform action paste: with sender <UIMenuController: 0x7227d30>.
cannot perform action delete: with sender <UIMenuController: 0x7227d30>.
cannot perform action promptForReplace: with sender <UIMenuController: 0x7227d30>.
cannot perform action _showMoreItems: with sender <UIMenuController: 0x7227d30>.
cannot perform action _setRtoLTextDirection: with sender <UIMenuController: 0x7227d30>.
cannot perform action _setLtoRTextDirection: with sender <UIMenuController: 0x7227d30>.
can perform action customCopy: with sender <UIMenuController: 0x7227d30>.
can perform action custom1: with sender <UIMenuController: 0x7227d30>.
cannot perform action custom2: with sender <UIMenuController: 0x7227d30>.
can perform action custom3: with sender <UIMenuController: 0x7227d30>.
can perform action custom4: with sender <UIMenuController: 0x7227d30>.
cannot perform action cut: with sender <UIMenuController: 0x7227d30>.
cannot perform action select: with sender <UIMenuController: 0x7227d30>.
cannot perform action selectAll: with sender <UIMenuController: 0x7227d30>.
cannot perform action paste: with sender <UIMenuController: 0x7227d30>.
cannot perform action delete: with sender <UIMenuController: 0x7227d30>.
cannot perform action promptForReplace: with sender <UIMenuController: 0x7227d30>.
cannot perform action _showMoreItems: with sender <UIMenuController: 0x7227d30>.
cannot perform action _setRtoLTextDirection: with sender <UIMenuController: 0x7227d30>.
cannot perform action _setLtoRTextDirection: with sender <UIMenuController: 0x7227d30>.