我试图从 VoiceOver 隐藏我的应用程序中的几个元素,以便屏幕阅读器不会大声朗读它们。在 iOS 上,我设置isAccessibilityElement为NO,但这对 OSX 没有影响。从 VoiceOver 隐藏元素的正确方法是什么?
例如,我在视图中包含了一系列标签,如果它们被 VoiceOver 单独朗读,则这些标签毫无意义。我想accessibilityLabel在容器视图上设置来描述嵌套在其中的所有标签。但是如果我这样做,里面的标签仍然会被 VoiceOver 读出。
In macOS, it is true that setting accessibilityElement to NO for NSButton, NSTextField and NSImageView has no effect. That is because these are controls – they inherit from NSControl. To make it work for controls, you must do it instead to the control's cell.
In an Objective-C project, I so subclassed several Cocoa controls. For example, whenever I want a image view to be skipped by VoiceOver, I set its Custom Class in Interface Builder to this:
/*!
@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
Run Code Online (Sandbox Code Playgroud)
小智 1
如果将元素的辅助功能角色设置为空字符串,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:@""];应该做同样的事情。
| 归档时间: |
|
| 查看次数: |
2419 次 |
| 最近记录: |