UICollectionViewFlowLayout Voice Over 使用 Flow Layout 无序读取项目 [英] UICollectionViewFlowLayout Voice Over reads items out of order with Flow Layout

查看:34
本文介绍了UICollectionViewFlowLayout Voice Over 使用 Flow Layout 无序读取项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个关于可访问性和 UICollectionViews 的问题,希望能得到一些专家的帮助.关于部分标题的另一个问题可以在此处找到.我创建了一个 示例项目来演示这两个问题.

I have two questions regarding accessibility and UICollectionViews that I'm hoping to get some expert help with. The other question, regarding section headers, can be found here. I've created a sample project demonstrating both issues.

我有一个 UICollectionView 使用 UICollectionViewFlowLayout 包含可变高度的项目.UIFlowLayout 将每一行的元素垂直居中.不幸的是,当 Voice Over 启用时,它似乎偏爱垂直放置更高的元素,导致它无法按顺序读取项目.

I have a UICollectionView using UICollectionViewFlowLayout that contains items of variable height. UIFlowLayout centers the elements on each row vertically. Unfortunately, when Voice Over is enabled, it seems to favor elements that are placed higher vertically, causing it to read items out of order.

您可以拉取这个示例项目,运行它,启用画外音,然后滑动查看要查看问题的项目.它创建具有随机高度的单元格,因此很可能会乱序读取单元格.

You can pull this example project, run it, enable voice over, and swipe through the items to see the issue. It creates cells with random heights, so it will very likely read the cells out of order.

有没有办法让集合视图按顺序浏览项目?我觉得这是唯一有意义的方法,但我找不到强制执行这种行为的方法.将集合视图设置为对子视图进行分组似乎没有帮助.任何帮助将不胜感激.

Is there a way I can make the collection view advance through the items sequentially? I feel like that is the only way that makes sense, but I can't find a way to enforce that behavior. Setting the collection view to group child views doesn't seem to help. Any help would be greatly appreciated.

推荐答案

摘自 iOS 辅助功能,VoiceOver 阅读顺序问题

在您的示例中实现此目的的最快方法是将三个标签放在一个透明的 UIView 子类中,作为标签的容器.这个子类必须正确设置才能让 VoiceOver 知道如何解释它.如果您的部署目标是 iOS6,那么您可以简单地回答这个子类中的应该对无障碍儿童进行分组"问题.

The quickest way to achieve this for your example is to place the three labels in a transparent UIView subclass to serve as a container for your labels. This subclass will have to be properly setup to let VoiceOver know how to interpret it. If your deployment target is iOS6 then you can simply answer the "should group accessibility children" question in this subclass.

-(BOOL)shouldGroupAccessibilityChildren{
     return YES;
 }

对于低于 iOS6 的情况会更复杂,除了您的 UIView 容器子类将仅包含作为辅助功能元素的 UILabels.你可以这样实现:

For below iOS6 it would be more complicated, except that your UIView container subclass would contain only UILabels which are accessibility elements. You could implement it like this:

 -(BOOL)isAccessibilityElement{
     return NO;
  }
  -(NSInteger)accessibilityElementCount{
       return self.subviews.count;
  }
  -(id)accessibilityElementAtIndex:(NSInteger)index{
      return [self.subviews objectAtIndex:index];
  }
  -(NSInteger)indexOfAccessibilityElement:(id)element{
      return [self.subviews indexOfObject:element];
  }

我已经测试了这个示例代码,它可以满足您的要求,如果您需要任何说明,请添加评论.总是乐于帮助使事情变得更易于访问.

I have tested this example code and it does what you are looking for, if you need any clarification please add a comment. Always happy to help make things more accessible.

这篇关于UICollectionViewFlowLayout Voice Over 使用 Flow Layout 无序读取项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆