ios - 旁白未检测到 UITextView (iOS 13) 中的链接
问题描述
旁白未检测到 UITextView (iOS 13) 中的链接
我有以下代码,它适用于 iOS 12 上的配音(即配音在向上/向下滑动时选择单个链接)但在 iOS 13 上向上/向下滑动不起作用
class ViewController: UIViewController {
@IBOutlet weak var myTextView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
let text = "Testing https://www.google.com/ in link and 904-567-5678 is phone number"
let attributedString = NSMutableAttributedString(string: text)
myTextView.attributedText = attributedString
myTextView.isUserInteractionEnabled = false
myTextView.isEditable = false
myTextView.isSelectable = true
myTextView.dataDetectorTypes = [.link,.phoneNumber]
myTextView.font = UIFont(name: myTextView.font!.fontName,
size: 25.0)
myTextView.backgroundColor = .red
}
func textView(_ textView: UITextView,
shouldInteractWith URL: URL,
in characterRange: NSRange,
interaction: UITextItemInteraction) -> Bool {
UIApplication.shared.open(URL, options: [:])
return false
}
}
解决方案
如果这在 iOS 13 中仍然不起作用,作为一种解决方法,您可以执行以下操作:
attributedString.addAttribute(.link, value: myLinkURL, range: NSRange(myLinkLocation...)
推荐阅读
- php - 我想在 php 中将 SimpleXMLElement 对象转换为 XML
- angular - Safari 中的 Ngx-chart 高度问题
- ember.js - Ember:无法识别 camelCase 助手引用
- tensorflow - 如何在bert中设置特定的gpu?
- python - 运输错误:运输错误(503,'search_phase_execution_exception')
- java - 如何使用正则表达式提取java方法参数
- abap - CL_SALV_BS_RUNTIME_INFO 通过 RFC 返回空引用
- r - 在 foreach 循环中并行执行 autoML 时出现 H2O“网格:无法将新模型附加到具有不同训练输入的网格”错误
- javascript - 即使 api 失败,也正在执行 fetch `then()`
- c# - WPF DataGrid 性能 - 过滤器性能