在VoiceOver - UIAccessibility期间,将可点击的焦点设置在UIAlertView的按钮元素上

时间:2014-12-31 10:37:12

标签: ios objective-c uialertview voiceover uiaccessibility

我打算在UIAccessibilityLayoutChangedNotification的按钮元素上使用UIAlertView设置辅助功能焦点(tappable focus)。为了保存对按钮的引用,它在下面的代码中实现:

UIAlertView *alert = [[[UIAlertView alloc] init] autorelease];
alert.delegate = self;
[alert setTitle:@"Title"];
[alert setMessage:@"Message"];

[alert addButtonWithTitle:@"Button"];
UIButton *yesButton = [alert.subviews lastObject];
[yesButton setHidden:NO];

myButton = [[UIButton buttonWithType:UIButtonTypeCustom] autorelease];
[myButton retain];
[alert addSubview:myButton];
[alert show];

[myButton setAccessibilityLabel:@"This is my button"];
[myButton setFrame:yesButton.frame];

[alert show];

如果VoiceOver正在运行,我希望可点击焦点位于按钮上,而不是标题元素。所以我在显示警报视图时执行此操作:

if(UIAccessibilityIsVoiceOverRunning()){
    UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, myButton);
}

但是,按钮的可访问性标签由VoiceOver读取(“这是我的按钮”),但是按钮上没有设置可点击的焦点,但仍保留在UIAlertView的标题元素上

1 个答案:

答案 0 :(得分:1)

你确定要打VoiceOver吗?用户能够非常快速地导航,部分原因是VoiceOver与用户界面的一致性。尽量不要通过改变默认值来阻止他们。

也就是说,您可以通过在出现警告视图后发布布局更改通知来覆盖默认的VoiceOver焦点。尝试从UIAlertViewDelegate-didPresentAlertView:开始。您可能还需要在发布通知之前等待一小段时间,以确保视图已完成并且VoiceOver已注意到。 dispatch_async()非常适合此目的。