UIBarButtonItem如何禁用无障碍功能(iOS)

4

所以,

我正在尝试禁用添加到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及其子视图的VoiceOver(期望的),但实际上没有成功(不期望的):

[legendMenuBarItem setIsAccessibilityElement:TRUE];
[legendMenuBarItem setAccessibilityElementsHidden:TRUE]; 

总之...我的问题是如何完全禁用可访问性交互?通常我使用setIsAccessibilityElement:FALSE,这很有效。但这次没有这样的好运。
谢谢!

我以为在故事板上会有可访问性选项可用于禁用导航栏按钮,但实际上只有某些元素显示该选项。 - undefined
请告诉我我的答案是否有效。@Kivak Wolf - undefined
@TejaNandamuri,你找到解决办法了吗? - undefined
1个回答

3

setAccessibilityElementsHidden仅在UI元素中确实有一些元素时才起作用。

尝试将setAccessibilityElementsHidden设置为YES,针对的是工具栏或包含您的工具栏按钮的容器。

编辑:如果您不想为特定的工具栏按钮启用辅助功能,则需要将该按钮添加到工具栏的辅助元素中,该元素是一个NSArray,然后根据需要隐藏它。

编辑:这会禁用导航项的可访问性。

  self.navigationController.navigationBar.accessibilityElementsHidden=YES;

我添加了以下代码行[self.navigationItem setAccessibilityElements:@[legendMenuBarItem]]; [self.navigationItem setAccessibilityElementsHidden:TRUE];但并没有产生任何影响。同样的情况也适用于self.navigationController.navigationBar - undefined
什么?...我试过了,对我有效。我将一个导航控制器嵌入到我的视图控制器中。 - undefined
你能否在你的故事板中发布视图层级的屏幕截图,用于你的视图控制器? - undefined
2
我不使用故事板,这完全是程序化的。我还在使用iOS 8.4。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接