【问题标题】:How to disable 'Replace' and 'Share' options on UITextField long press?如何禁用 UITextField 长按上的“替换”和“共享”选项?
【发布时间】:2016-06-18 12:13:29
【问题描述】:

在 UITextField 长按上,除了“剪切”、“复制”、“粘贴”和“定义”选项之外,现在还有一些选项,即“替换...”和“共享...”。可以通过“canPerformAction:withSender”方法禁用这些“剪切”、“复制”、“粘贴”和“定义”选项,但我找不到禁用这些“替换...”和“共享”的方法。 ..' 选项。是否也有任何可用的选择器,或者可以通过其他任何方式禁用它?有人遇到过这个并成功禁用了这些选项吗?请提出建议。

【问题讨论】:

    标签: ios uitextfield editing


    【解决方案1】:

    您可以拦截长按事件并为您提供自己的实现和所需的行为。 请检查接受的答案:
    How to intercept long press on UITextView without disabling context menu?
    或提供允许的操作

    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
        if (action == @selector(copy:) ||
            action == @selector(selectAll:)) {
            return true;
        }
    
        return false;
    }
    

    更多详情:How to disable copy paste option from UITextField programmatically

    【讨论】:

    • 您好,感谢您的回复,但正如我在问题中提到的,我知道这是禁用“剪切”、“复制”、“粘贴”、“选择”、“全选”的方法选项,但我想禁用我无法通过“canPerformAction:withSender”方法实现的“替换”和“共享”选项。
    【解决方案2】:

    聚会迟到了,但一种选择是使用动作的描述。 Apple 尚未将 Share 暴露为 UIResponderStandardEditActions 项目之一。所以解决方法是使用action's description。不是一个优雅的解决方案,但应该可以解决问题:

    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
            if action == #selector(UIResponderStandardEditActions.copy(_:)) ||
               action.description.contains("_share") { // disabling share
                   return false
            } else {
                   return super.canPerformAction(action, withSender: sender)
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多