长按 UITextView 时“NSAttributedString.Key.link”值可见。我怎样才能停止向用户显示它

问题描述 投票:0回答:1

我有一个 UITextView,其中包含带有多个链接的属性文本,这些链接具有单独的键值,并且这些链接具有单击操作。

当我长按链接文本并移动时,我可以看到“NSAttributedString.Key.link”的值。 我要么必须禁用长手势,要么隐藏“NSAttributedString.Key.link”的值。 任何建议我怎样才能实现这一目标。

let linkString = NSMutableAttributedString(string: name)
linkString.addAttribute(NSAttributedString.Key.link, value: "name:\(userID)_section:\(section)", range: NSMakeRange(0, name.count))

我使用上面的代码来创建链接 我尝试删除 UITextView 上的长按手势,但没有成功

ios swift uitextview uilongpressgesturerecogni
1个回答
0
投票

如果我理解正确,您不想在长按链接时显示菜单。当

UITextItemInteraction
presentActions
被调用时,我们返回
false
以禁用交互

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    switch interaction {
    case .invokeDefaultAction:
        print(URL)
        return true
    case .presentActions, .preview:
        return false
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.