Adding Accessibility to piano style UI element - ios

I'm trying to make a musical keyboard UI element accessible. Just like how GarageBand does it. In other words, at first touch user is told by VoiceOver that they are touching a musical keyboard, and from that point every tap on musical keyboard view plays notes and there’s no further VoiceOver interruptions until user touches outside of the musical keyboard frame.
I have a UICollectionView where each cell represents a musical key and when user taps on it notes are played as expected. However, I have trouble getting this to work like the GB does. For the UICollectionView object, I’ve set accessibilityLabel and have set accessibilityTraits to UIAccessibilityTraitAllowsDirectInteraction. But that doesn’t seem to work. It doesn’t play any notes when VoiceOver is on. On the first tap VoiceOver anounces whatever the accessibilityLabel is set to and then just beeps on every tap.
I have custom UIGestureRecogniser subclass that I use for the collection view cell tap detection. Do I need to do something special under these circumstances?
Any ideas? Do I need to be doing anything else?

Figured it out. Not sure what the reasoning is however.
Embeded the musical keyboard UICollectionView in another view and made that view accessible with the UIAccessibilityTraitAllowsDirectInteractiontrait. Now it works as expected.

Related

Custom Keyboard Accessory view input

I have created a custom accessory view to supplement the standard Apple alpha iOS keyboard.
The purpose is to add a line of numeric keys to prevent flipping back and forth between keyboard views. At first, I created a toolbar and loaded it with a set of 0 - 9 titled buttonItems and it functioned quite well. However, it looked terrible, not at all like the alpha keys despite adding a rounded rect background image to each key because the system apparently prevents customizing font size and button spacing inside the stack view of the toolbar. Therefore, I created a UIView xib and loaded it with a stackView full of customized numerical buttons. When I add the UIView as the accessory view it looks pretty darn close to the rest of the Apple Alpha keyboard. The issue now is that the touch-up events go to the UIView class of the accessory view. Is there a clever, efficient way to have the button presses in the accessory emulate the std keyboard feeding into TextField: shouldChangeCharactersIn? I could package the button presses into a local notification event to get it into the class holding the textField but that seems terribly inelegant! Any suggestions would be greatly appreciated. Stay Safe!
Not the best answer, but I did implement notification on key button press with an observer in the main view class. The observer does a TextField.insertText which is suboptimal since I will need to refactor the several hundred lines of code that performs real-time language translation in the shouldChangeCharacters methods. Ah well.

ios voiceover slider double tap and hold, but for custom view

I've created a custom view that acts like a UISlider - there is a "track", and a handle to "grab" to change the value. For particular reasons, I can't just make it a subclass of UISlider. I'm trying to make this slider as accessible as possible with VoiceOver. I have accessibilityIncrease and accessibilityDecrease on my custom view that handle single finger drag up and single finger drag down. This changes the value of the slider by 10% at a time.
However, I'd like to allow more fine grained control, just like a non-VoiceOver slider. By default , UISlider has double tap and hold, and you can drag up/down to "pan" the slider. I'd like to add exactly that to my custom view, but I can't find the correct incantation to handle the double tap and hold gesture.
Is there something I can do to mimic the double tap and hold gesture from UISlider on my custom view?
Thanks very much!!!
If you want to implement this kind of new gesture for VoiceOver users, just forget it.
The recommended gesture for this kind of UI control is definitely the implementation of adjustable value as you already did apparently.
I don't think it's a good idea to try and implement new VoiceOver gestures in an application because its users have their habits and they may be totally lost with your customed control if they cannot handle it unless you add an hint to explain but that's definitely not what I recommend anyway.
Otherwise, you could take a look at the pass through concept introduced in the What's New in Accessibility WWDC 2017 video that deals with the same idea but for a panning gesture...

Accessibility voiceover single swipe gestures in Swift IOS

I am working on the IOS application, related to voice over, my Question is : When accessibility voice over was enabled how can i get the swipe gestures left, right, top and down, what re the function for detecting these in swift?
First of all, you need to let VoiceOver know that about your view (or another element). So if you are in a view controller, this should work: self.view.isAccessibilityElement = true
Second, you need to let VoiceOver know that your view will handle user interactions on its own: self.view.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction. After that your view should start getting gestures notifications.
Here's another relevant answer: https://stackoverflow.com/a/20712889/2219578
It isn't possible to catch the left, right, top and bottom VoiceOver gestures : I've seen neither a protocol nor a kind of notification for this.
However, you can detect a scrolling action and be aware of the element focus provided by VoiceOver.

What makes an element accessible? And why are tap gestures less accessible than UIButtons? How do I fix it?

Brent Simmons wrote in a blog post that tap gesture recognizers, presumably on a UIView, are less accessible than UIButtons. I'm trying to learn my way around making my app accessible, and I was curious if anyone could clarify what makes that less accessible than a UIButton, and what makes an element "accessible" to begin with?
For more customizability I was planning to build a button comprised of a UIView and tap gesture recognizers with some subviews, but now I'm not so sure. Is it possible to make a UIView as accessible as a UIButton?
Accessible in this context most likely refers to UI elements that can be used using Apple's accessibility features, such as VoiceOver (see example below).
For example, a visually impaired person will not be able to see your view or subviews, or buttons for that matter; but the accessibility software "VoiceOver" built into every iOS device will read to her/him the kind of object and its title, something like "Button: Continue" (if the button title is "Continue").
You can see that most likely the tap gesture recognizer will not be read by VoiceOver and thus be less "accessible".

when VoiceOver is on, is there a way an app can detect a single-finger (left-right)swipe?

When VoiceOver is active on an iOS device, the single-finger swipe(left or right) gesture allows users to browse the different elements in the view. Is there a way to detect if a user used the single-finger swipe gesture when using voiceover?
You might be asking either of 2 things:
You want to know when the VoiceOver user successfully issued the single-finger swipe left/right gesture to VoiceOver - VoiceOver will process ("steal") the gesture from your code and do its thing (move VoiceOver cursor to the next/previous element). The closest you can get is to get notifications for a UIView when the VoiceOver cursor lands on it or leaves it (see the UIAccessibilityFocus protocol).
You want to make part of your UI not subject to VoiceOver gestures (VoiceOver will not process ("steal") gestures in this area) so that you can detect the gestures yourself (including the single-finger swipe left/right) in a standard way and process them in the way you want for your app. Then you must add the UIAccessibilityTraitAllowsDirectInteraction trait to the accessibilityTraits property to the relevant UIView (see UIAccessibility protocol for more details). A prominent example of where this is used is in GarageBand for iOS - the piano keyboard or drums have this trait so that VoiceOver user can play on the instruments without turning VoiceOver off.
I ended up creating a category/extension on UIView and overriding accessibilityElementDidBecomeFocused().
Here I can get a global hook, which gets called every time the accessibility state has changed.
Swift example:
extension UIView {
//MARK: Accessibility
override public func accessibilityElementDidBecomeFocused() {
super.accessibilityElementDidBecomeFocused()
UIApplication.sharedApplication().sendEvent(UIEvent())
}
}

Resources