所以,
我正在尝试禁用我已添加到 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,但即使在当前设置中,当我点击按钮时它仍然显示“Legend”。
我尝试过的更多场景:
这会禁用所有语音(需要)但仍然允许按钮进行交互(不需要):
[legendMenuBarItem setAccessibilityLabel:@" "];
[legendMenuBarItem setIsAccessibilityElement:TRUE];
[legendMenuBarItem setAccessibilityTraits:UIAccessibilityTraitNone];
据推测,这应该为 UIBarButtonItem 和它的 subview 禁用 VoiceOver(需要)但它不会(不需要):
[legendMenuBarItem setIsAccessibilityElement:TRUE];
[legendMenuBarItem setAccessibilityElementsHidden:TRUE];
总而言之...我的问题是如何完全禁用可访问的交互性?通常我使用 setIsAccessibilityElement:FALSE
并且效果很好。但这次没有这样的运气。
谢谢!
最佳答案
setAccessibilityElementsHidden
仅在该 UIElement 确实包含一些元素时才起作用。
尝试将工具栏或栏按钮所在的容器的 setAccessibilityElementsHidden
设置为 YES
。
编辑:如果您不想要特定栏按钮的可访问性,那么您需要将该按钮添加到工具栏的可访问性元素(NSArray
),然后将其隐藏为根据您的要求。
编辑:这禁用了导航项的可访问性
self.navigationController.navigationBar.accessibilityElementsHidden=YES;
关于ios - UIBarButtonItem 如何禁用辅助功能 (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32256952/