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

时间:2015-08-27 18:30:35

标签: ios objective-c accessibility uibarbuttonitem

SO,

我正在尝试禁用UIBarButtonItem的VoiceOver辅助功能,我已将其添加到UINavigationController的leftBarButtonItems中。虽然我可以为没有标题的按钮禁用它,但我似乎无法禁用带有标题的按钮。例如:

// 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并且效果很好。但这次没有这样的运气。

谢谢!

1 个答案:

答案 0 :(得分:1)

只有当UIElement中确实包含一些元素时,function Warrior(weaponName) { this.weapon = weaponName; } Warrior.prototype = { getWeapon : function() { return this.weapon; }, setWeapon : function(value) { this.weapon = value; }, displayInfo : function() { return { "weapon" : this.getWeapon() }; } }; //---------------------------------- function Archer(weaponName) { Warrior.call(this, weaponName); this.accuracy = "86%"; } Archer.prototype = Object.create(Warrior.prototype); Archer.prototype.constructor = Archer; Archer.prototype.getAccuracy = function() { return this.accuracy; }; Archer.prototype.setAccuracy = function(value) { this.accuracy = value; }; Archer.prototype.displayInfo = function() { return "weapon: " + this.getWeapon() + ", accuracy: " + this.getAccuracy(); }; //---------------------------------- var w = new Warrior("sword"); var a = new Archer("axe"); console.log(w.displayInfo()); // Object {weapon: "sword"} console.log(a.displayInfo()); // weapon: axe, accuracy: 86% 才有效。

尝试setAccessibilityElementsHiddensetAccessibilityElementsHidden获取工具栏或存在条形按钮的容器。

修改:如果您不想要特定栏按钮的辅助功能,则需要将该按钮添加到工具栏的辅助功能元素YES,然后将其隐藏根据您的要求。

修改:此导航项目已禁用辅助功能

NSArray