【发布时间】:2011-07-07 17:14:03
【问题描述】:
当您添加多个自定义菜单项时,显然曾经有一个easy way 来防止“更多...”标签出现在 UIMenuController 中。您只需删除所有系统菜单项。甚至还有一个 workaround here 仍然有复制工作。您只需使用不同的选择器实现自定义复制命令,然后覆盖 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: 时得到的输出:请注意,“复制:”操作永远不会调用该方法:
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>.
【问题讨论】:
-
显然没有办法从 Objective-C 中的 UIMenuController 中删除副本,但可以使用 CSS:
-webkit-user-select:none;iphonedevsdk.com/forum/iphone-sdk-development/… -
也许我在开头的段落不够清楚,但我并没有试图阻止用户选择。我试图在 UIMenuController 中放置多个自定义菜单项,而不会卡在“更多...”菜单下。您以前可以通过阻止显示复制命令 (stackoverflow.com/questions/4311009/…) 来做到这一点,但这不再有效。
-
“不再有效”是什么意思?它是在 iOS5 中坏了还是什么?
-
“不再有效”是指此处发布的解决方案:stackoverflow.com/questions/3255070/… 不起作用。它显然曾经。其他人 (stackoverflow.com/questions/4311009/…) 也发现此解决方案不起作用。正如我在更新中提到的,“复制:”永远不会调用被覆盖的方法。
-
@Ifalin 你终于找到新版本的解决方案了吗?
标签: ios cocoa-touch uimenucontroller