如何使 UITextView 中的属性字符串可访问? [英] How to make attributed string within a UITextView accessible?

查看:22
本文介绍了如何使 UITextView 中的属性字符串可访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,屏幕阅读器将选择整个视图,并且无法通过双击来跟踪链接.事实上,在可访问性检查器上按下激活会使应用程序委托崩溃,而控制台中没有任何堆栈跟踪.我试过在 UITextView 本身中搞乱可访问性特征,但我没有任何运气.

let quoteAttributedStr = NSMutableAttributedString(string: "This is a test String" + " ")let enableLinkText = NSAttributedString(string: "this is the clickable text", attributes: dummyLinkAttribute)quoteAttributedStr.append(enableLinkText)返回quoteAttributedStr

解决方案

问题涉及

  1. 链接上方会出现一种弹出窗口.
  2. 操作表出现后,向右滑动以获取 Open 操作.
  3. 双击打开 URL 并进入第 7 步的最后一个屏幕.

按照上面的代码片段,您可以使 UITextView 中的属性字符串可访问并通过双击打开它并按住直到弹出窗口出现在您的链接上方(这就是 VoiceOver 的工作原理).

By default the screen reader will select the entire view, and the link isn't able to be followed on a double tap. In fact, pressing activate on the accessibility inspector crashes the app delegate without any stack trace in the console. I've tried messing with the accessibility traits within the UITextView itself but I didn't have any luck.

let quoteAttributedStr = NSMutableAttributedString(string: "This is a test String" + " ")
                let enableLinkText = NSAttributedString(string: "this is the clickable text", attributes: dummyLinkAttribute)
                quoteAttributedStr.append(enableLinkText)

                return quoteAttributedStr

解决方案

The problem deals with a specific VoiceOver gesture to be used when a link must be activated in a UITextView.

I created a blank project (iOS 12, Xcode 10) including the code snippet hereafter to get 2 URLs in the myTextView element :

class TextViewURLViewController: UIViewController, UITextViewDelegate {

    @IBOutlet weak var myTextView: UITextView!

    let myString = "Follow this developers guide if you already know the VoiceOver gestures."
    let myDevURL = "https://a11y-guidelines.orange.com/mobile_EN/dev-ios.html"
    let myGesturesURL = "https://a11y-guidelines.orange.com/mobile_EN/voiceover.html"


    override func viewDidLoad() {

        let attributedString = NSMutableAttributedString(string: myString)

        attributedString.addAttribute(.link,
                                      value: myDevURL,
                                      range: NSRange(location: 12,
                                                     length: 17))

        attributedString.addAttribute(.link,
                                      value: myGesturesURL,
                                      range: NSRange(location: 52,
                                                     length: 19))

        myTextView.attributedText = attributedString
        myTextView.font = UIFont(name: myTextView.font!.fontName,
                                 size: 25.0)
    }


    func textView(_ textView: UITextView,
                  shouldInteractWith URL: URL,
                  in characterRange: NSRange,
                  interaction: UITextItemInteraction) -> Bool {

        UIApplication.shared.open(URL, options: [:])
        return false
    }
}

Follow the steps hereunder to activate the link :

  1. Get the rotor links item with the appropriate gesture.
  2. Swipe up or down with one finger to reach the link.
  3. Double tap and hold until the event on step 4.

  1. A kind of popup shows up above the link.
  2. Once the action sheet appears, flick right to get the Open action.
  3. Double tap to open the URL and get the last screen on step 7.

Following the code snippet above, you can make attributed string within a UITextView accessible and open it by double tapping + holding until the popup appears above your link (this is how VoiceOver works).

这篇关于如何使 UITextView 中的属性字符串可访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆