【问题标题】:Voice over doesn't detect links in UITextView (iOS 13)旁白未检测到 UITextView (iOS 13) 中的链接
【发布时间】:2020-07-29 20:58:32
【问题描述】:

旁白未检测到 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 swift uitextview voiceover uiaccessibility


    【解决方案1】:

    如果这在 iOS 13 中仍然无法正常工作,作为一种解决方法,您可以这样做:

    attributedString.addAttribute(.link, value: myLinkURL, range: NSRange(myLinkLocation...)

    【讨论】:

      【解决方案2】:

      请在此处查看我的答案:https://stackoverflow.com/a/66155952/4600723

      iOS 13+ 上的 UITextView 的行为与 iOS 12 不同。我使用的修复方法是设置 isEditable = true,然后正确检测到 Voice Over 用户的链接(对于非 VO 用户,您需要处理委托方法保持 UITextView 不可编辑。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-07-07
        • 2013-09-28
        • 2012-11-01
        • 1970-01-01
        • 2013-11-24
        • 1970-01-01
        • 2013-10-29
        • 1970-01-01
        相关资源
        最近更新 更多