UIButton voice assistance on demand with VoiceOver enabled

大城市里の小女人 提交于 2019-12-11 10:34:34

问题


I would like to ask how to design voice over assistance on demand with VoiceOver enabled.

I have such code to create UIButton:

_myLocationButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_myLocationButton setImage:[UIImage imageNamed:@"my_location_icon"] forState:UIControlStateNormal];
_myLocationButton.accessibilityLabel = @"My location";
_myLocationButton.accessibilityHint = @"Double tap to hear where You are, in which zone or near zone and floor information in building";
[_myLocationButton addTarget:self
                      action:@selector(myLocationButtonPressed)
            forControlEvents:UIControlEventTouchUpInside];

Now in myLocationButtonPressed method I have such code:

UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, positionDescription);

My question is. When I'm trying to double tap when myLocationButton is active the VoiceOver is saying only: "My location". What I would like is after double tapping I'd like to hear positionDescription not button accessibilityLabel. I know that method myLocationButtonPressed is invoking but from unknown reason posting UIAccessibilityAnnouncementNotification event do nothing and I can't hear anything.

Can somebody give me some advice how to approach this kind of problem.


回答1:


The only way I've found to get announcements to read out consistently, is to post the notification with a delay. This function should help.

- (void)postVoiceOverAnnouncement:(NSString*)message withDelay:(int)seconds {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(seconds * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"This will get read out");
    });
}

Even with adding the starts media session trait, something is still interrupting the announcement. What you have to watch out for, is the length of your delay. If someone continues to swipe through your app, they could interrupt the announcement. Though, since in a properly accessible application, this information should be available elsewhere, they should be able to find it again. This is of course just a helpful announcement, so as not to shift focus around on unsuspecting VoiceOver users :).

Another problem with your code I noticed:

_myLocationButton.accessibilityHint = @"Double tap to hear where You are, in which zone or near zone and floor information in building";

First off, bravo for including such detailed hints! However, you should not include the "Double tap to...." portion. Users know how to interact with buttons through VoiceOver. Is this the only way to interact with this? Or might one also hit enter on an external keyboard? What about some other hypothetical AT in which the selection gesture is some other interaction... How useful is this hint for someone using a Braille Board??? Just inform the users of the consequence of interacting with the object, let the AT take care of the rest.



来源:https://stackoverflow.com/questions/32334096/uibutton-voice-assistance-on-demand-with-voiceover-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!