0

I have one text (ASTextNode)

let contentNode = ASTextNode()

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

and in contentNode have link

I setup touchUpInSide for contentNode

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)
}

when i tapped to contentNode i want to change maximumNumberOfLines to see all text, but it's not smooth. I just try UIView.animate but it's not effect.

And when i tapped to link in contentNode, it't call both 2 function contentNodeTapped and tappedLinkAttribute.

How to when tapped link only call tappedLinkAttribute.

Text after tapped

Text after tapped

Text after tapped

1 Answers1

0

i believe you can't do that, instead you need to use ASEditableTextNode and use ASEditableTextNodeDelegate to capture event when url tapped

you can call

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

  // your action here

   return true
}

you need to make sure your ASEditableTextNode styling look like your current ASTextNode

Wendy Liga
  • 634
  • 5
  • 12