/*!
@brief Image view which will be skipped over by VoiceOver
@details Be careful that you *really* want the view to be skipped over by
VoiceOver, because its meaning is conveyed in a better, non-visual way,
elsewhere. Remember that not all VoiceOver users are completely blind.
*/
@interface SSYNoVoiceOverImageView : NSImageView {}
@end
@implementation SSYNoVoiceOverImageView
- (void)awakeFromNib {
self.cell.accessibilityElement = NO;
}
@end
2 回答
在macOS中,为
NSButton
,NSTextField
和NSImageView
设置accessibilityElement
为NO
确实无效 . 那是因为这些是控件 - 它们继承自NSControl
. 要使其适用于控件,您必须改为控件的 cell .在Objective-C项目中,我将几个Cocoa控件子类化 . 例如,每当我想要VoiceOver跳过图像视图时,我在Interface Builder中将其自定义类设置为:
如果将元素的辅助功能角色设置为空字符串,则Voice Over将不会检测到它 . 我不得不在我的应用程序中隐藏一些NSImageView元素,因为它们的文件名被读出来并且让VO用户感到困惑 .
或
[element accessibilitySetOverrideValue:@"" forAttribute:NSAccessibilityRoleAttribute];
要不然
[[element cell] accessibilitySetOverrideValue:@"" forAttribute:NSAccessibilityRoleAttribute];
应该做的伎俩 .
我知道Apple是一种基于Accessibility API的新方法,但它只适用于OS X 10.10以及我正在使用的应用程序需要与10.9兼容 .
如果你可以使用新的API
[element setAccessibilityRole:@""];
或[[element cell] setAccessibilityRole:@""];
应该做同样的事情 .