I have a button that can toggle a label being shown:
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
button.accessibilityLabel = "You can tap this really long string that i'm testing"
label.accessibilityLabel = "This is a label"
}
@IBAction func buttonTapped(_ sender: UIButton) {
label.isHidden = !label.isHidden
if !label.isHidden {
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, label)
}
}
}
When tapping the button, if the label is shown I activate the label to be read by VoiceOver. The problem is VoiceOver automatically starts reading the button's accessibilityLabel
when the user taps the button. This results in VoiceOver reading half of the button's accessibilityLabel
before swapping to reading the label's accessibilityLabel
(e.g. "You can tap this really...This is a label").
Is there a way I can know when VoiceOver is done reading the button's accessibilityLabel
and only then call UIAccessibilityPostNotification
? Or is there a way to disable the button from being read again by VoiceOver when the user taps the button?
An example project can be seen here: https://github.com/rajohns08/VoiceOverTest