首页 > 解决方案 > 自定义视图(如收藏视图)上的辅助功能旁白

问题描述

目前我正在研究自定义视图。

我需要在标准 UICollectioView 中实现 VoiceOver 的行为。当我将焦点从自定义视图层次结构之外的元素转换为层次结构中的元素时,VoitserOver 读取自定义视图的可访问性标签,然后读取所选视图的可访问性标签

@interface FBMinimizedPlayerControlPanelView ()

@property (nonatomic, strong) ImageView *artworkView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *subtitleLabel;
@property (nonatomic, strong) ImageContainer *togglePlayPauseButton;

@end

@implementation FBMinimizedPlayerControlPanelView

- (instancetype)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }

    return self;
}

- (void)setUp {

//    self.isAccessibilityElement = YES;
    self.accessibilityLabel = @"Miniplayer.";
    self.accessibilityHint = @"Double tap to expand the miniplayer.";
//    self.accessibilityElementsHidden = YES;

//set up code 

    [self.togglePlayPauseButton configureWithAccessibilityLabel:@"Play" forState:BEToggleButtonStateSelected];
    [self.togglePlayPauseButton configureWithAccessibilityLabel:@"Pause" forState:BEToggleButtonStateNormal];

}

- (nullable NSArray *)accessibilityElements {


    return @[self.togglePlayPauseButton];
}

@end

现在,当我打开 VoiceOver 时,它只读取暂停/播放按钮,但我希​​望行为与 UICollectionView 中的一样,在开始时读取collectionView 的accessibilityLabel,然后读取item accessibilityLabel。

例如:collectionView accessibilityLabel:“collectionView”,单元格的内容标签accessibilityLabel:“单元格的内容标签”,

在我上面描述的 VoiceOver 红色的情况下,它就像:“collectionView,单元格的内容标签”(仅当先前的焦点不是 collectionView 的子视图时);

标签: iosuikitaccessibilityvoiceover

解决方案


为了让 VoiceOver 能够很好地分析,集合视图可以被视为一个数组,一旦使用adjustabletrait 定义就应该遍历该数组。

然后必须将集合视图的每个元素定义为UIAccessibilityElement.

要了解应该如何实现,我建议您看一下WWDC 2018 - Deliver an exceptional accessibility experience视频,其内容在这里完美总结,并且可以下载其演示的示例。


推荐阅读