How to detect touch on NSTextAttachment

前端 未结 7 914
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 03:24

What is the best way to detect when user taps on NSTextAttachment on iOS?

I think that one of the ways would be checking for the character on carret\'s

7条回答
  •  被撕碎了的回忆
    2020-12-14 03:47

    Swift 3 answer:

    func textView(_ textView: UITextView, shouldInteractWith textAttachment: NSTextAttachment, in characterRange: NSRange) -> Bool {
        return true
    }
    

    Make sure your textView isEditable = false, isSelectable = true, and isUserInteractionEnabled = true. Duncan's answer did not mention isUserInteractionEnabled, this has to be true, otherwise it wont work.

    You can do this programmatically (textView.isEditable = false), or via attributes inspector:

提交回复
热议问题