我打算在 UIAlertView
的按钮元素上使用 UIAccessibilityLayoutChangedNotification
设置辅助功能焦点(可点击焦点)。为了保存对按钮的引用,在下面的代码中实现了它:
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 正在运行,我希望可点击的焦点位于按钮而不是标题元素上。所以我在显示警报 View 时这样做:
if(UIAccessibilityIsVoiceOverRunning()){
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, myButton);
}
但是,按钮的辅助功能标签由 VoiceOver 读出(“这是我的按钮”),但可点击的焦点并未设置在按钮上,而是保留在 UIAlertView
的标题元素上>
最佳答案
你确定要对抗 VoiceOver 吗?用户能够非常快速地导航,部分原因是 VoiceOver 遍历用户界面的一致性。尽量不要通过更改默认值来妨碍他们。
也就是说,您可以通过在警报 View 出现后发布布局更改通知来覆盖默认的 VoiceOver 焦点。尝试从您的 UIAlertViewDelegate 的 -didPresentAlertView:
执行此操作.您可能还需要在发布通知之前稍等片刻,以确保 View 已完成显示并且 VoiceOver 已注意到。 dispatch_async()
非常适合此目的。
关于ios - 在 VoiceOver 期间将可点击焦点设置在 UIAlertView 的按钮元素上 - UIAccessibility,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27719912/