[英]TouchUpInside without LinkAttribute in ASTextNode
I have one text (ASTextNode) 我有一个文本(ASTextNode)
let contentNode = ASTextNode()
contentNode.maximumNumberOfLines = 7
contentNode.truncationMode = .byTruncatingTail
contentNode.isUserInteractionEnabled = true
contentNode.delegate = self
and in contentNode have link 并且在contentNode中有链接
I setup touchUpInSide for 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)
}
when i tapped to contentNode i want to change maximumNumberOfLines to see all text, but it's not smooth. 当我点击contentNode我想更改maximumNumberOfLines以查看所有文本,但它不顺利。 I just try UIView.animate but it's not effect.
我只是尝试UIView.animate,但它没有效果。
And when i tapped to link in contentNode, it't call both 2 function contentNodeTapped
and tappedLinkAttribute
. 当我点击链接contentNode时,它不会同时调用2函数
contentNodeTapped
和tappedLinkAttribute
。
How to when tapped link only call tappedLinkAttribute
. 如何点击链接只调用
tappedLinkAttribute
。
Text after tapped 点击后的文字
i believe you can't do that, instead you need to use ASEditableTextNode
and use ASEditableTextNodeDelegate
to capture event when url
tapped 我相信你不能这样做,而是你需要使用
ASEditableTextNode
并使用ASEditableTextNodeDelegate
在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
您需要确保您的
ASEditableTextNode
样式看起来像您当前的ASTextNode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.