I know I can simulate a button tap with something like:
buttonObj.sendActions(for: .touchUpInside)
but that actually taps the button and doesn't activate the element for VoiceOver. I want to programmatically tap the element as if a user taps on it with their finger while VoiceOver is on - so VoiceOver should start reading the accessibilityLabel
of the item, but not actually perform the action of the item yet.
You want to ACCESSIBILITY_FOCUS the item. You can do this with Accessibility Notifications.
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,
elementYouWantToFocus);
Please note that shifting accessibility focus around on users is in most cases going to make things less accessible. If your user interface is well structured, users should be able to find the content for themselves. Even new content. Major context changes and such should be announced, and in general iOS default behaviors are going to be more accessible, because they are what users will be accustomed to.
https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior.html
I have also covered this topic in more depth on this blog post.