我有一个文本(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 函数contentNodeTapped
和tappedLinkAttribute
.
如何在点击链接时只调用tappedLinkAttribute
.
点击后的文字