[英]TouchUpInside without LinkAttribute in ASTextNode
我有一个文本(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
。
点击后的文字
我相信你不能这样做,而是你需要使用ASEditableTextNode
并使用ASEditableTextNodeDelegate
在url
tapped时捕获事件
你可以打电话
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
// your action here
return true
}
您需要确保您的ASEditableTextNode
样式看起来像您当前的ASTextNode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.