问题
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.
回答1:
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.
回答2:
You have to override default behaviour to select either UITextViews test or link you have provided. See this class UIAccessibilityElement
. Hope this helps you
回答3:
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 :
- Get the rotor
links
item with the appropriate gesture. - Swipe up or down with one finger to reach the link.
- Double tap and hold until you see the screen on step 4.
- A kind of popup shows up above the link.
- Once the action sheet appears, flick right to get the
Open
action. - 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.
来源:https://stackoverflow.com/questions/39522364/uitextview-linkable-label-accessibility-voice-over-issue