ios - UIBarButtonItem 如何禁用辅助功能 (iOS)

标签 ios objective-c accessibility uibarbuttonitem

所以,

我正在尝试禁用我已添加到 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/

相关文章:

ios - Xcode12 - 为 iOS 模拟器构建,但链接为 macOS 构建的目标文件,文件 'dir/SomeFile.a' 用于架构 x86_64

ios - SKCloudServiceController().requestUserToken 在 iOS 14.2 上卡住

html - 文章页面中的 H1 - 站点标题或文章标题?

iOS - 如何重新初始化表格 View 单元格

IOS/ Storyboard/自动布局 : Make Textview Expand Vertically to Accomodate Text

objective-c - 如何在外部文件中存储字符串以在整个应用范围内使用(iOS)

iphone - 如何在 UIView 下绘制阴影?

ios - 设置段颜色的tintColor时如何停止导航栏TintColor的变化?

css - 如何测试正在开发的网页的视觉可访问性?

iOS VoiceOver – 在标准 UIView 中实现 “x of y” 读出?