Disable / hide accessibility element

痞子三分冷 提交于 2020-12-05 11:24:07

问题


I'm trying to hide several elements in my app from VoiceOver so that they don't get read aloud by the screen reader. On iOS, I'd set isAccessibilityElement to NO, but this has no effect on OSX. What's the correct way to go about hiding elements from VoiceOver?

For example, I have a series of labels contained inside a view that make no sense if they're spoken separately by VoiceOver. I'd like to set the accessibilityLabel on the container view to describe all the labels nested within. But if I do that, the labels inside are still read out by VoiceOver.


回答1:


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



回答2:


If you set an element's accessibility role to an empty string, Voice Over won't detect it. I had to hide some NSImageView elements in my app because their file names were being read out and it was confusing for the VO user.

Either

[element accessibilitySetOverrideValue:@"" forAttribute:NSAccessibilityRoleAttribute];

or else

[[element cell] accessibilitySetOverrideValue:@"" forAttribute:NSAccessibilityRoleAttribute];

should do the trick.

I know that Apple a new method based Accessibility API but it only works for OS X 10.10 onwards and the application I'm working needs to be compatible with 10.9.

If you can use the new API [element setAccessibilityRole:@""]; or [[element cell] setAccessibilityRole:@""]; should do the same thing.



来源:https://stackoverflow.com/questions/31523333/disable-hide-accessibility-element

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!