简体   繁体   中英

UITextView Linkable label Accessibility Voice Over Issue

I have a UITextView and portion of the text is clickable. Link works. When I turn the accessibility feature in settings of the iPhone and turn on Voice over as well, the text of the textview is read out but the link is not working. The accessibility feature on storyboard of the textview is enabled and also link is selected under accessibility attributes and the link does not work when voice over is turned on. I have also tried adding isAccessbilityElement = true to the textview and ended up with no luck.

UITextView is added to the custom cell on a table view.

Thanks in advance for your suggestions.

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 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 you see the screen 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.

最后三个步骤的描述

The only thing to remember is the double tap and hold until the popup appears above your link .

The solution depends on the iOS version you are using. For iOS 12. * the answer https://stackoverflow.com/a/55144836/4600723 is correct.

For iOS 13+ the situation is a bit more complicated and you need to think out of the box here. I found out that setting isEditable = true and overriding the delegate method:

func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
    false
}

(to turn enditing off) will provide the behavior you are looking for.

Generally speaking, UITextView from the accessibility point of view is really buggy.

I do not have solution. I still looking for.

For now I use UIWebview in my app instead of UITextView. UIWebview is more efficient with UIAccessiblity.

You have to override default behaviour to select either UITextViews test or link you have provided. See this class UIAccessibilityElement . Hope this helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM