0

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

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

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

我也尝试过NSAccessibilityRoleDescriptionAttributeNSAccessibilityTitleAttribute属性。

4

1 回答 1

0

您可能需要在方法中进行子类化NSWebView和覆盖:NSAccessibilityRoleDescriptionAttribute- (id)accessibilityAttributeValue:(NSString *)attribute

- (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;
}
于 2013-05-30T22:18:30.647 回答