你怎么真的从UIMenuController删除复制 [英] How do you REALLY remove Copy from UIMenuController

查看:512
本文介绍了你怎么真的从UIMenuController删除复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显然以前是一个简单方法,以防止在添加多个自定义菜单项时,更多...标签显示在UIMenuController中。你只需要删除所有的系统菜单项。甚至有一个这里的解决方法仍然有复制工作。您只需要使用不同的选择器实现自定义复制命令,然后覆盖canPerformAction:withSender:不显示系统副本:

   - (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{
if(action == @selector(copy :))
return NO;
else
//显示或隐藏其他事物的逻辑
}

不幸的是这个方法不再工作(至少在UIWebView子类)。 canPerformAction:withSender:为除copy之外的每个系统菜单项调用:因此结果是系统复制菜单项始终显示。这意味着如果你有多个自定义菜单项,它们总是隐藏在更多...之后



因此,有没有办法真正删除系统的复制项目或某些其他方式,以防止菜单项隐藏在更多...之后?



更新 b

这是我覆盖canPerformAction时得到的输出:withSender:注意,对于copy:操作,该方法从未被调用:

 无法执行操作cut:with sender< UIMenuController:0x7227d30> ;. 
无法执行操作select:with sender< UIMenuController:0x7227d30> ;.
无法执行操作selectAll:with sender< UIMenuController:0x7227d30> ;.
无法执行操作粘贴:with sender< UIMenuController:0x7227d30> ;.
无法执行操作delete:with sender< UIMenuController:0x7227d30> ;.
无法执行操作promptForReplace:with sender< UIMenuController:0x7227d30> ;.
无法执行操作_showMoreItems:with sender< UIMenuController:0x7227d30> ;.
无法执行操作_setRtoLTextDirection:with sender< UIMenuController:0x7227d30> ;.
无法执行操作_setLtoRTextDirection:with sender< UIMenuController:0x7227d30> ;.
可以执行操作customCopy:with sender< UIMenuController:0x7227d30> ;.
可以执行操作custom1:with sender< UIMenuController:0x7227d30> ;.
无法执行操作custom2:with sender< UIMenuController:0x7227d30> ;.
可以执行操作custom3:with sender< UIMenuController:0x7227d30> ;.
可以执行操作custom4:with sender< UIMenuController:0x7227d30> ;.
无法执行操作cut:发送方< UIMenuController:0x7227d30> ;.
无法执行操作select:with sender< UIMenuController:0x7227d30> ;.
无法执行操作selectAll:with sender< UIMenuController:0x7227d30> ;.
无法执行操作粘贴:with sender< UIMenuController:0x7227d30> ;.
无法执行操作delete:with sender< UIMenuController:0x7227d30> ;.
无法执行操作promptForReplace:with sender< UIMenuController:0x7227d30> ;.
无法执行操作_showMoreItems:with sender< UIMenuController:0x7227d30> ;.
无法执行操作_setRtoLTextDirection:with sender< UIMenuController:0x7227d30> ;.
无法执行操作_setLtoRTextDirection:with sender< UIMenuController:0x7227d30> ;.


解决方案

您链接的技术似乎仍然有效。我用这些方法实现了一个 UIWebView 子类,只有A和B项出现。

  +(void)initialize 
{
UIMenuItem * itemA = [[UIMenuItem alloc] initWithTitle:@Aaction:@selector(a :)];
UIMenuItem * itemB = [[UIMenuItem alloc] initWithTitle:@Baction:@selector(b :)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:itemA,itemB,nil]];
[itemA release];
[itemB release];
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
BOOL can = [super canPerformAction:action withSender:sender] ;
if(action == @selector(a :) || action == @selector(b :))
{
can = YES;
}
if(action == @selector(copy :))
{
can = NO;
}
NSLog(@%@执行动作%@与发件人%@。,可以@can:@can not,NSStringFromSelector(action)
return can;
}


There apparently used to be an easy way to prevent the "More..." label from appearing in UIMenuController when you added more than one custom menu item. You just had to remove all of the system menu items. There was even a workaround here for still having copy work. You just had to implement a custom copy command using a different selector and then override canPerformAction:withSender: to not show the system copy:

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender 
{
    if (action == @selector(copy:))
       return NO;
    else
       // logic to show or hide other things
}

Unfortunately this method no longer works (at least in a UIWebView subclass). canPerformAction:withSender: is called for every system menu item except copy: so the result is that the system copy menu item is always displayed. This means that if you have more than one custom menu item, they are always hidden behind "More..."

So, is there a way to really remove the system's copy item or some alternate way to prevent menu items from hiding behind "More..."?

Update

This is the output I get when I override canPerformAction:withSender: notice that the method is never called for the "copy:" action:

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>.

解决方案

The technique you linked to still seems to work. I implemented a UIWebView subclass with these methods, and only the A and B items appeared.

+ (void)initialize
{
    UIMenuItem *itemA = [[UIMenuItem alloc] initWithTitle:@"A" action:@selector(a:)];
    UIMenuItem *itemB = [[UIMenuItem alloc] initWithTitle:@"B" action:@selector(b:)];
    [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:itemA, itemB, nil]];
    [itemA release];
    [itemB release];
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    BOOL can = [super canPerformAction:action withSender:sender];
    if (action == @selector(a:) || action == @selector(b:))
    {
        can = YES;
    }
    if (action == @selector(copy:))
    {
        can = NO;
    }
    NSLog(@"%@ perform action %@ with sender %@.", can ? @"can" : @"cannot", NSStringFromSelector(action), sender);
    return can;
}

这篇关于你怎么真的从UIMenuController删除复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆