UIBarButtonItem怎么禁用辅助功能(IOS)

本教程将介绍UIBarButtonItem如何禁用辅助功能(IOS)的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。

UIBarButtonItem怎么禁用辅助功能(IOS) 教程 第1张

问题描述

所以,

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

我尝试了各种方法禁用画外音,但即使在当前设置中,当我点击按钮时仍显示"图例"。

我尝试过的更多方案:

这将禁用所有语音(需要),但仍允许按钮是交互式的(不需要):

[legendMenuBarItem setAccessibilityLabel:@" "]; 
[legendMenuBarItem setIsAccessibilityElement:TRUE];
[legendMenuBarItem setAccessibilityTraits:UIAccessibilityTraitNone];

这应该会禁用UIBarButtonItem及其子视图的画外音(需要),但它不会(不需要):

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

总而言之.我的问题是,世界上到底怎么才能完全禁用可访问的交互性呢?通常我使用setIsAccessibilityElement:FALSE,效果很好。但这次就没有这么好的运气了。

谢谢!

推荐答案

setAccessibilityElementsHidden仅当该UI元素中确实包含某些元素时才有效。

尝试setAccessibilityElementsHiddenYES工具栏或工具栏按钮所在的容器。

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

编辑:这将禁用导航项目的辅助功能

  self.navigationController.navigationBar.accessibilityElementsHidden=YES;

好了关于UIBarButtonItem怎么禁用辅助功能(IOS)的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。