Disable / hide accessibility item

I am trying to hide several items in my app from VoiceOver so that they are not read aloud by a screen reader. On iOS, I installed isAccessibilityElement

in NO

, but this does not affect OSX. What's the correct way to hide items from VoiceOver?

For example, I have a series of shortcuts contained within a view that don't make sense if they speak apart from VoiceOver. I would like to set accessibilityLabel

in the container view to describe all nested labels. But if I do that, the labels inside are still read by VoiceOver.

+3


source to share


2 answers


On macOS it is true that setting is accessibilityElement

on NO

for NSButton

, NSTextField

and has NSImageView

no effect. This is because they are controls - they inherit from NSControl

. To make it work for controls you have to do this instead of the control...

In an Objective-C project, I have subclassed several Cocoa controls like this. For example, whenever I want an image to be skipped with VoiceOver, I set it to Custom Class in Interface Builder:



/*!
 @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

      

+3


source


If you set the accessibility role of an item to an empty string, Voice Over will not detect it. I had to hide some NSImageView items in my application because their filenames were being read and it was confusing for the VO user.

Or

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

or more



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

must do the trick.

I know Apple is the new Access API, but it only works for OS X 10.10 and the app I am working must be 10.9 compatible.

If you can use the new API [element setAccessibilityRole:@""];

or [[element cell] setAccessibilityRole:@""];

should do the same.

+2


source







All Articles