自定义视图(如集合视图)上的辅助功能VoiceOver

时间:2018-09-13 08:54:26

标签: ios uikit accessibility voiceover

目前,我正在使用自定义视图。

我需要实现VoiceOver的行为,就像在标准UICollectioView中一样。当我将焦点从自定义视图层次结构之外的元素转换为层次结构中的元素时,VoitserOver会先读取自定义视图的accessibilityLabel,然后读取所选视图的accessibilityLabel

@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,然后读取项目accessibilityLabel。

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

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

1 个答案:

答案 0 :(得分:0)

为便于VoiceOver进行分析,收集视图可能被视为一个数组,一旦定义了adjustable特性,就应该遍历该数组。

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

要了解应如何实施,建议您看一下WWDC 2018 - Deliver an exceptional accessibility experience视频,其视频内容得到了here的完美总结,展示的示例可以为downloaded