选中后,NSWebView会覆盖VoiceOver

我有一个 NSWebView ,当我在 Mac OS X 上使用VoiceOver时,它宣布 NSWebView 选项为“ HTML 内容”这很可能会让最终用户感到困惑,因为我将它用于自定义控件,而且我已经处理了所有其他可访问性方面的问题 . NSWebView 正确 .

如何覆盖VoiceOver为 NSWebView 宣布的内容?我尝试了以下但是它没有任何区别:

[webView accessibilitySetOverrideValue:@"Map View" forAttribute:NSAccessibilityDescriptionAttribute];

我还尝试了 NSAccessibilityRoleDescriptionAttributeNSAccessibilityTitleAttribute 作为属性 .

回答(1)

2 years ago

您可能需要在 - (id)accessibilityAttributeValue:(NSString *)attribute 方法中继承 NSWebView 并覆盖 NSAccessibilityRoleDescriptionAttribute

- (id)accessibilityAttributeValue:(NSString *)attribute
{
    id value = nil;

    if ( [attribute isEqualToString:NSAccessibilityRoleDescriptionAttribute] )
    {
        value = @"Map View";
    }
    // all your other ifs here
    else
    {
        value = [super accessibilityAttributeValue:attribute];
    }

    return value;
}

请确保您告诉 NSAccessibility 您提供的内容(特别是 NSAccessibilityRoleDescriptionAttribute 部分):

- (NSArray *)accessibilityAttributeNames
{
    static NSMutableArray *attributes = nil;

    if ( attributes == nil )
    {
        attributes = [[super accessibilityAttributeNames] mutableCopy];

        NSArray *additionalAttributes = @[NSAccessibilityDescriptionAttribute, NSAccessibilityRoleAttribute, NSAccessibilityChildrenAttribute, NSAccessibilityTitleUIElementAttribute, NSAccessibilityRoleDescriptionAttribute];

        for ( NSString *attribute in additionalAttributes )
        {
            if ( ![attributes containsObject:attribute] )
            {
                [attributes addObject:attribute];
            }
        }
    }

    return attributes;
}