Strangely when I was testing accessibility voice-over for UISlider value changes using Accessibility inspector I could not get updated (changed) slider value announcement.
Initially I had project requirement of a custom view with pan gesture to increment and decrement (before-after) image slider. But here i am posting code same situation when I made a demo application with simple UISlider. So that it will be easy to debug.
class ViewController: UIViewController {
@IBOutlet weak var simpleSlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
simpleSlider.accessibilityLabel = "Slider example"
simpleSlider.accessibilityTraits = .adjustable
simpleSlider.accessibilityValue = percentOf(value: simpleSlider.value) // 1.
}
@IBAction func sliderAction(_ sender: UISlider) {
simpleSlider.accessibilityValue = percentOf(value: sender.value) // 2.
UIAccessibility.post(notification: .layoutChanged, argument: simpleSlider) // 3.
}
func percentOf(value: Float?) -> String {
return UInt((value ?? 0.0) * 100.0).description
}
}
Here,
- I have initialised slider value 50% and voice over correctly announced.
- Update new value from slider and assign to accessibility valie
- Without notification, it never announces any value. (see the screenshot below).
** Here slider updated either 'increment' from traits or manually, the voice over still announces 50% instead of say 70% value. i.e new value is updated as expected but it is not announced and instead old value is announced on every time update.**
