首页 文章

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

提问于
浏览
2

目前我正在开发自定义视图 .

我需要像标准UICollectioView一样实现VoiceOver的行为 . 当我将焦点从我的自定义视图层次结构之外的元素转换为层次结构中的元素时,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”,单元格的内容标签accessibilityLabel:“单元格的内容标签”,

在我上面描述的VoiceOver red的情况下,它就像:“collectionView,cell的内容标签”(仅当以前的focus不是来自collectionView的子视图时);

1 回答

  • 0

    要通过VoiceOver进行良好分析,可以将集合视图视为一旦使用 adjustable trait定义就应遍历的数组 .

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

    为了理解应该如何实现,我建议你看看 WWDC 2018 - Deliver an exceptional accessibility experience 视频,其内容完美地概括为here,其显示的示例可以是downloaded .

相关问题