画外音只能看到一个uicollectionview的页面

人气:565 发布:2022-10-16 标签: ios cocoa-touch uicollectionview voiceover uiaccessibility

问题描述

所以我有一个 UICollectionView,其中包含一组使用自定义 UILayout 显示的 UICollectionViewCell.

So i have a UICollectionView with a set of UICollectionViewCells displayed using a custom UILayout.

我已将 UILayout 配置为所有 UICollectionViewCell 的布局几乎与它们在 ios 上的照片应用中的布局完全相同.

I've configured the UILayout to lay out all the UICollectionViewCells almost exactly the same as how they are laid out in the photos app on ios.

问题是,当语音打开时,用户正在使用滑动遍历 UICollectionViewCells,当用户到达页面上的最后一个可见单元格并尝试向前滑动到下一个单元格时,它只是停止.

The problem is, it seems when voice over is turned on, and the user is traversing through the UICollectionViewCells using swipe, when the user gets to the last visible cell on the page, and tries to swipe forward to the next cell, it simply stops.

我知道在 UITableView 中单元格会一直向前移动,并且表格视图会自动向下滚动.

I know that in UITableView the cells will just keep moving forward, and the table view will scroll down automatically.

有谁知道如何获得这种行为?

Does anyone know how to get this behaviour?

推荐答案

这个答案也对我有用.谢谢!

This answer worked for me, too. Thanks!

您必须启用另一个调用才能使其正常工作.否则,您的方法 (void)accessibilityElementDidBecomeFocused 将永远不会被调用.您必须在对象 Cell 上启用可访问性.

There is one other call you must have enabled to get this to work. Otherwise your method (void)accessibilityElementDidBecomeFocused will never get called. You must enable accessibility on the object Cell.

选项 1:在 ViewController 中,将单元格实例设置为具有可访问性.

Option 1: In ViewController, set the cell instance to have accessibility.

Cell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
[cell setIsAccessibilityElement:YES];

选项2:在单元格对象中实现无障碍界面:

Option 2: Implement the accessibility interface in the cell object:

- (BOOL)isAccessibilityElement
{
    return YES;
}

- (NSString *)accessibilityLabel {
    return self.label.text;
}

- (UIAccessibilityTraits)accessibilityTraits {
    return UIAccessibilityTraitStaticText;  // Or some other trait that fits better
}

- (void)accessibilityElementDidBecomeFocused
{
    UICollectionView *collectionView = (UICollectionView *)self.superview;
    [collectionView scrollToItemAtIndexPath:[collectionView indexPathForCell:self] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally|UICollectionViewScrollPositionCenteredVertically animated:NO];
    UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self);
}

983