单元事件不适用于ASTextNode的isUserInteractionEnabled = true

时间:2018-07-11 06:15:29

标签: swift asyncdisplaykit

我尝试将此代码用于ASTextNode上可链接的cell

https://stackoverflow.com/a/41617801/1979953

引用代码

func addLinkDetection(_ text: String, highLightColor: UIColor, delegate: ASTextNodeDelegate) {
    self.isUserInteractionEnabled = true
    self.delegate = delegate

    let types: NSTextCheckingResult.CheckingType = [.link]
    let detector = try? NSDataDetector(types: types.rawValue)
    let range = NSMakeRange(0, text.characters.count)
    if let attributedText = self.attributedText {
        let mutableString = NSMutableAttributedString()
        mutableString.append(attributedText)
        detector?.enumerateMatches(in: text, range: range) {
            (result, _, _) in
            if let fixedRange = result?.range {
                mutableString.addAttribute(NSUnderlineColorAttributeName, value: highLightColor, range: fixedRange)
                mutableString.addAttribute(NSLinkAttributeName, value: result?.url, range: fixedRange)
                mutableString.addAttribute(NSForegroundColorAttributeName, value: highLightColor, range: fixedRange)

            }
        }
        self.attributedText = mutableString
    }        
}

我发现cell不能用isUserInteractionEnabled = true的{​​{1}}轻敲。

然后,ASTextNode仅在func textNode(_ textNode: ASTextNode, tappedLinkAttribute attribute: String, value: Any, at point: CGPoint, textRange: NSRange)中的录音链接部分被调用。

  • 如何通过点击事件到达ASTextNode下方?
  • cell中的所有点击是否都有delegate,不仅链接了一部分?

0 个答案:

没有答案