Show / hide accessibility items in overflow menu when opening custom UITableViewCell
Im implementing accessibility in a custom class UITableViewCell
. I have a fairly simple overflow menu with a few buttons inside it that are hidden until the ellipsis button is pressed, which will open and close the overflow.
In my cell's initializer I'm setting accessibilityElementsHidden
mine overflowContainer
to YES
. This seems to work, when scrolling with VoiceOver these views are skipped.
Then, opening the cell, in the animation completion handler UIView
, I set the accessibilityElementsHidden
same overflowContainer
to NO. This doesn't seem to have any effect, these items are still being skipped.
I've also tried posting UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil)
before / after / on change accessibilityElementsHidden
BOOL
, but that doesn't make any difference either.
Basically Id like to switch accessibilityElementsHidden
to a couple of instances UIView
at a certain point. Can anyone tell me what I might be doing wrong?
Here is the code I run when the overflow is opened:
- (void)cellOverflowDidShow:(MyCell *)cell
{
self.overflowContainer.isAccessibilityElement = YES;
self.firstButton.isAccessibilityElement = YES;
self.secondButton.isAccessibilityElement = YES;
self.thirdButton.isAccessibilityElement = YES;
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.firstButton);
}
I'm running the opposite when the cell is closed (set everything to NO
and send notification again). And when initializing the cell, all I set was:
self.overflowContainer.isAccessibilityElement = NO;
Absolutely not sure why it shouldn't work, it seems like I'm doing everything 100% right. If I don't set a string in the initializer, all buttons are available (all the time). So it seems that the first call, whether YES
or not NO
, works, but any subsequent ones are ignored.
source to share
In the visible state, you declare the overflow container as an accessibility item. This way, VoiceOver will allow the user to focus instead of navigating through the child elements. Instead of toggling the accessibility element, keep self.overflowContainer.isAccessibilityElement
on NO
and toggle the accessibility of its children, firstButton, secondButton, and thirdButton.
The shorthand for setting child accessibility is accessibilityElementsHidden
. Try setting self.overflowContainer.accessibilityElementsHidden
to NO
when the view appears and YES
when it disappears.
You may still need to trigger a layout change notification, regardless.
source to share