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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…