我需要UITextView
使用超链接和电话号码而不使用上下文菜单(复制粘贴等)&没有选择(选择指标)。我已经尝试过这个代码在iOS 10中运行良好,但在iOS 11.3中无法正常工作
extension UITextView {
override open func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) {
if gestureRecognizer.isKind(of: UILongPressGestureRecognizer.self) {
let array = gestureRecognizer.value(forKey: "_targets") as! NSMutableArray
let targetAndAction = array.firstObject
let actions = ["action=oneFingerForcePan:",
"action=_handleRevealGesture:",
"action=loupeGesture:",
"action=longDelayRecognizer:"]
for action in actions {
print("targetAndAction.debugDescription: \(targetAndAction.debugDescription)")
if targetAndAction.debugDescription.contains(action) {
gestureRecognizer.isEnabled = false
}
}
}
}
}
我还搜索过并发现在canperform
自定义类中覆盖了UITextView
,但这也无效。
现在有什么更好的方式。