那么,
我正在尝试禁用已添加到 UINavigationController 的 leftBarButtonItems 中的 UIBarButtonItem 的 VoiceOver 可访问性。虽然我可以为没有标题的按钮禁用它,但我似乎无法为有标题的按钮禁用它。例如:
// Create the legend UIBarButtonItem
UIBarButtonItem *legendMenuBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Legend" style:UIBarButtonItemStylePlain target:tool action:@selector(activate)];
// Should disable accessibility on the button, still enabled for subviews
[legendMenuBarItem setIsAccessibilityElement:FALSE];
// Remove "button" from VoiceOver speech for the button
[legendMenuBarItem setAccessibilityTraits:UIAccessibilityTraitNone];
// Removed "Legend" from being spoken, but the button is still tappable in accessibility mode
[legendMenuBarItem setAccessibilityLabel:@" "];
// Attempt to remove any accessibility elements... no real effect
[legendMenuBarItem setAccessibilityElements:nil];
// Supposedly this should disable all subviews from being accessible? Doesn't work...
[legendMenuBarItem setAccessibilityElementsHidden:TRUE];
// Add legend UIBarButtonItem to the end of the leftBarButtonItems
NSMutableArray *currentLeftBarItems = [NSMutableArray arrayWithArray:[self.navigationItem leftBarButtonItems]];
[currentLeftBarItems addObject:legendMenuBarItem];
[self.navigationItem setLeftBarButtonItems:currentLeftBarItems];
我尝试了各种方法来禁用 VoiceOver,但即使在当前设置中,当我点击按钮时,它仍然显示“图例”。
我尝试过的更多场景:
这会禁用所有语音(需要),但仍然允许按钮进行交互(不需要):
[legendMenuBarItem setAccessibilityLabel:@" "];
[legendMenuBarItem setIsAccessibilityElement:TRUE];
[legendMenuBarItem setAccessibilityTraits:UIAccessibilityTraitNone];
据说,这应该禁用 UIBarButtonItem 及其子视图的 VoiceOver(所需),但事实并非如此(不需要):
[legendMenuBarItem setIsAccessibilityElement:TRUE];
[legendMenuBarItem setAccessibilityElementsHidden:TRUE];
总之......我的问题是如何完全禁用可访问的交互性?通常我使用
setIsAccessibilityElement:FALSE
,效果很好。但这次就没那么幸运了。
谢谢!
setAccessibilityElementsHidden
仅在 UIElement 中确实包含一些元素时才起作用。
尝试对工具栏或栏按钮所在的容器进行
setAccessibilityElementsHidden
到 YES
。
编辑:如果您不希望特定栏按钮的可访问性,那么您需要将该按钮添加到工具栏的可访问性元素(即
NSArray
)中,然后根据您的要求隐藏它。
编辑:这禁用了导航项的辅助功能
self.navigationController.navigationBar.accessibilityElementsHidden=YES;