0

我有一个文本(ASTextNode)

let contentNode = ASTextNode()

contentNode.maximumNumberOfLines = 7
contentNode.truncationMode = .byTruncatingTail
contentNode.isUserInteractionEnabled = true
contentNode.delegate = self

并且在 contentNode 中有链接

我为 contentNode 设置了 touchUpInSide

contentNode.addTarget(self, action: #selector(contentNodeTapped), forControlEvents: .touchUpInside)

@objc func contentNodeTapped() {

    if contentNode.maximumNumberOfLines == 7 {
      contentNode.maximumNumberOfLines = 0
    } else {
      contentNode.maximumNumberOfLines = 7
    }
    UIView.animate(withDuration: 0.2, delay: 0, options: [UIView.AnimationOptions.layoutSubviews], animations: {
      self.contentNode.setNeedsLayout()
      self.contentNode.layoutIfNeeded()
    }, completion: nil)

}

func textNode(_ textNode: ASTextNode!, tappedLinkAttribute attribute: String!, value: Any!, at point: CGPoint, textRange: NSRange) {
    guard let url = value as? URL else { return }
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

当我点击 contentNode 时,我想更改 maximumNumberOfLines 以查看所有文本,但它并不流畅。我只是尝试 UIView.animate 但它没有效果。

当我点击链接 contentNode 时,它​​不会同时调用 2 函数contentNodeTappedtappedLinkAttribute.

如何在点击链接时只调用tappedLinkAttribute.

点击后的文字

点击后的文字

点击后的文字

4

1 回答 1

0

我相信你不能那样做,相反你需要在被点击时使用ASEditableTextNode和使用ASEditableTextNodeDelegate来捕获事件url

你可以打电话

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {

  // your action here

   return true
}

你需要确保你的ASEditableTextNode造型看起来像你现在的ASTextNode

于 2019-07-20T15:56:08.557 回答