Reputation: 4677
I am trying to add iOS accessibility support/Voice Over to my app. My main screen has three main controls, but the third control is hosted within an embedded view controller.
I am setting accessibility elements in prepareForSegue and have confirmed that the embedded view controller controls are all loaded. Problem is I can still only select the first two controls which are in the enclosing view controller.
self.view.accessibilityElements =
@[
self.cmdMenu, // works
self.collectionView, // works
self.childViewController.peerMenu // doesn't work
];
All three views have isAccessibilityElement = YES.
Am I missing something? I can't imagine that there is a restriction on the accessibility elements being in the same view controller.
Upvotes: 6
Views: 8581
Reputation: 4677
I found my bug and now have Voice Over working. In the process I figured out a number of things that I would like to share.
self.view.accessibilityElements = @[ _control1, childViewController.view, childViewController2.view]
.childViewController.view.isAccessibilityElement = NO
.UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self)
. The notification argument (where I'm sending self
) tells Voice Over where it should position its cursor when the notification completes.UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, messageText)
. One caveat, this won't read aloud the messageText unless there is no other Voice Over in progress. You need to manage the timing yourself. Submitted a bug on this. Apple could make this a lot better.UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, messageText)
you can listen for UIAccessibilityAnnouncementDidFinishNotification
, but unfortunately this notification has almost no value. You only will get notified if your messageText was fully spoken. It doesn't tell you that it was spoken, but interrupted, and it will also not get triggered for any text spoken through the UIKit framework.UIAccessibility.h
header. If you are embarking on UIAccessibility support, it is a good read.Upvotes: 16