gpt4 book ai didi

ios - 具有辅助功能的 UITableViewCell 中的 UICollectionView

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:10 25 4
gpt4 key购买 nike

我正在为我的 iOS 应用程序添加辅助功能支持,但在我的一个表格 View 单元格中使用 Collection View 时遇到了问题。

例如,当用户从第一个单元格(水平)滚动到第二个单元格时,辅助功能仍会读取第一个单元格的内容。如果我尝试点击第二个单元格中的 View ,它会突出显示第二个单元格左侧的空白区域(第一个单元格将在此处但不再可见)并读取第一个单元格的内容。

当 Collection View 在 TableView 单元格(即 UIView 的 subview )中时,这不会发生。

我怀疑这与调用 UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification) 有关,我尝试在许多不同的地方调用它,但没有任何效果。

以下两个屏幕截图显示了 UIView 中的 Collection View 。辅助功能已启用,因此在点击时它会被选中并带有黑色边框。

  1. 当用户点击第一个单元格时,它将被选中。

  1. 当用户点击“下一步”,转到第二个单元格并点击该单元格时,将选择新单元格。

接下来的两个屏幕截图显示了 TableView 单元格内的 Collection View 。

当用户点击第一个单元格时,它会被选中并且 VoiceOver 正确地读出“我是标签 0”。

但是,当用户点击“下一步”,转到下一个单元格,然后点击第二个单元格时,它不会被选中,VoiceOver 仍会读出“我是标签 0”。

代码可用here on github .

最佳答案

我遇到了类似的问题,我最终解决了。我认为您的元素与

不匹配
isAccessibilityElement = true 

彼此之上。

我有一个垂直滚动的 TableView ,每个单元格包含一个标题和水平滚动的 Collection View 。

我仅在标题和 Collection View 单元格上将 isAccessibilityElement 设置为 true,在其余部分设置为 false

然后,我将 UICollectionView 子类化并覆盖以下 NSObject 方法:

func accessibilityElementCount() ->  Int
func accessibilityElement(at: Int) -> Any?
func index(ofAccessibilityElement element: Any) -> Int

它基本上只是告诉旁白您的 Collection View 具有这些可访问元素。 Collection View 本身不可访问,这不是问题,恰恰相反。你可能会使用

open var accessibilityElements: [Any]?

相反。

以下是文档 (UIAccessibility.h) 的更多阅读内容:

UIAccessibilityContainer methods can be overridden to vend individual elements that are managed by a single UIView.

For example, a single UIView might draw several items that (to an end user) have separate meaning and functionality. It is important to vend each item as an individual accessibility element.

Sub-elements of a container that are not represented by concrete UIView instances (perhaps painted text or icons) can be represented using instances of UIAccessibilityElement class (see UIAccessibilityElement.h).

Accessibility containers MUST return NO to -isAccessibilityElement.

为了允许漂亮的三指画外音滚动,您可能需要覆盖

func accessibilityScroll(_ direction: UIAccessibilityScrollDirection) -> Bool

以及相应地滚动您的收藏 View 。

关于ios - 具有辅助功能的 UITableViewCell 中的 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38820299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com