禁用在UITextView中剪切和复制,即使允许用户编辑文本 [英] Disable Cut and Copy in UITextView even after allowing the user to edit the text

查看:122
本文介绍了禁用在UITextView中剪切和复制,即使允许用户编辑文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我有一个 UITextView 可以编辑。我有另一个按钮复制,所以我想禁用内置的复制和剪切功能的文本视图。
当在文本视图内双击时,它们显示为黑色的迷你popover。是否有任何方法只阻止这两个选项,仍然让用户编辑文本?

I have a UITextView which can be edited. I have another button for "Copy", so I want to disable the built-in "Copy" and "Cut" features of the text view. These are shown as a black mini popover when double tapping inside the text view. Is there any way to block only these two options and still let the user edit the text?

推荐答案

覆盖 canPerformAction:withSender:方法为您不想允许的操作返回 NO

overrides the canPerformAction:withSender: method to return NO for actions that you don't want to allow:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        if (action == @selector(paste:))
            return NO;
        if (action == @selector(select:))   
            return NO;   
        if (action == @selector(selectAll:))   
            return NO;  
        return [super canPerformAction:action withSender:sender];
    }

另一种方式 b

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    if (menuController) {
        [UIMenuController sharedMenuController].menuVisible = NO;
    }
    return NO;
}

同时检查此链接

这篇关于禁用在UITextView中剪切和复制,即使允许用户编辑文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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