I have a bunch of buttons on the screen which are positioned intuitively visually but are not read in an intuitive order by VoiceOver. This is because certain buttons like Up and Down are placed above and below each other. However, voiceover starts reading from Left to Right, from Top to Bottom, it seems.
This results in voiceover reading the button to the right of "Up" after "Up", instead of reading "Down" immediately afterward.
How do I force voiceover to read the button that I want to read? I should mention that I'm using the swipe-to-cycle-through-elements feature on voiceover.
All my buttons are subclassed versions of UIView and UIButton. Here's an example of a button initiator I use. Ignore the pixel count - I know that's bad form but I'm in a pinch at the moment:
UIButton* createSpecialButton(CGRect frame,
NSString* imageName,
NSString* activeImageName,
id target,
SEL obClickHandler)
{
UIButton* b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:[GlobalHelper nonCachedImage:imageName ofType:@"png"]
forState:UIControlStateNormal];
[b setImage:[GlobalHelper nonCachedImage:activeImageName ofType:@"png"]
forState:UIControlStateHighlighted];
[b addTarget:target action:obClickHandler forControlEvents:UIControlEventTouchUpInside];
b.frame= frame;
return b;
}
- (UIButton *) createSendButton {
CGFloat yMarker = 295;
UIButton* b = createSpecialButton(CGRectMake(160, yMarker, 70, 45),
@"Share_Btn",
@"Share_Selected_Btn",
self,
@selector(sendAction));
b.accessibilityHint = @"Send it!";
b.accessibilityLabel = @"Stuff for voiceover to be added";
[self.view addSubview:b];
return b;
}
I know this is an old thread, but I found that the easiest way to do it is to subclass UIView as such (Swift 3). Then simply modify your main UIView type in storyboard to AccessibiltySubviewsOrderedByTag and update the tags in each subview you want read in order.
class AccessibilitySubviewsOrderedByTag: UIView {
}
This doesn’t directly answer the original question, but it answers the title of the question:
When I want VoiceOver to swipe down a column, I have been using a containing view for the column with
shouldGroupAccessibilityChildren
set.I wish I had known this earlier, because it can be a pain to retroactively insert containers into an autolayout situation…
I found a convenience way yesterday. Similar to @TejAces ' answer. Make a new swift file, then copy these things into it.
Set the UIView(contains views you want to reorder)'s class as ReorderAccessibilityByStoryBoardView. Then you can reorder them by reordering storyboard's view list.
Because subview doesn't contain views in StackView/ScrollView, you need to make a independent class in this file. Such as the ReorderAccessibilityByStoryBoardStackView down below.
With these codes, you can also reorder view's added in code by adding them in a specific order.
The easiest answer to this lies in creating a
UIView
subclass that contains your buttons, and responds differently to the accessibility calls from the system. These important calls are:I've seen a few of these questions, and answered one before, but I've not seen a generic example of how to reorder the VoiceOver focus. So here is an example of how to create a
UIView
subclass that exposes its accessible subviews to VoiceOver by tag.AccessibilitySubviewsOrderedByTag.h
AccessibilitySubviewsOrderedByTag.m
Now simply enclose your buttons in an instance of this view, and set the tag property on your buttons to be essentially the focus order.
You can change the order setting the view's accessibilityElements array:
or
If you need to set the interaction enabled programmatically:
If the view is hidden the voice over will not pass through it.
In Swift you just have to set view's accessiblityElements array property:
view.accessibilityElements = [view1, view2, view3]
// order you wish to have