以编程方式确定 VoiceOver 读取 UIView 项目的顺序

发布于 2024-11-28 10:00:33 字数 223 浏览 3 评论 0原文

我正在使我的 iPhone 应用程序易于访问。 VoiceOver 令人印象深刻。当用户使用 VoiceOver 时,它会自动读出屏幕上的项目,并允许用户双击屏幕上的任意位置来选择该项目。但是,我希望 VoiceOver 按特定顺序读取项目,但它始终从 UINavigationBar 项目(包括后退按钮)开始。我根本不希望这些项目被阅读,我只想从特定项目开始。是否有“firstResponder”的 VoiceOver 等效项?

I am making my iPhone app accessible. VoiceOver is pretty impressive. When a user uses VoiceOver, it automatically reads off the items on the screen and allows the user to double-tap anywhere on the screen to select that item. However, I want VoiceOver to read the items in a specific order, but it always begins with the UINavigationBar items including the back button. I don't want these items not to be read at all, I just want to start with a specific item. Is there a VoiceOver-equivalent of "firstResponder"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

病女 2024-12-05 10:00:33

是的,

有一个名为 UIAccessibilityContainer 的协议,它是由 NSObject 实现的。它使您能够使用以下三种方法自定义容器行为:

  • accessibilityElementCount
  • accessibilityElementAtIndex:
  • indexOfAccessibilityElement:

如果您有一个要控制的主视图您只需实现这三个方法并返回合适的视图/索引即可访问元素的顺序。另一件事是容器视图本身不能是辅助功能元素,因此您应该覆盖 isAccessibilityElement: 并返回 NO

- (BOOL)isAccessibilityElement {
    return NO;
}

示例实现

我建议您要么按照您希望的显示顺序拥有所有视图的数组,要么使用 tag 属性(如果您不将其用于其他任何用途)。协议的实现变得超级简单。

元素数组

我假设您有一个名为 accessibleElements 的数组,它以正确的顺序存储元素。

- (NSInteger)accessibilityElementCount {
    return self.accessibleElements.count;
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
    return self.accessibleElements[index]; 
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
    return [self.accessibleElements indexOfObject:element];
}

标记元素

我假设您的子视图从 0 到子视图的数量连续标记。

- (NSInteger)accessibilityElementCount {
    return self.subviews.count;
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
    // Not that self should have a tag<0 or tag>count otherwise it will 
    // return itself for that tag instead of the element you want it to.
    return [self viewWithTag:index]; 
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
    return ((UIView *)element).tag;
}

Yes

There is a protocol called UIAccessibilityContainer that is implemented by NSObject. It enables you to customize the container behaviour using these three methods:

  • accessibilityElementCount
  • accessibilityElementAtIndex:
  • indexOfAccessibilityElement:

If you have a main view where you want to control the order of the accessibility elements you would just implement these three methods and return the suitable view/index. One more thing is that the container view cannot be an accessibility element itself so you should override isAccessibilityElement: and return NO;

- (BOOL)isAccessibilityElement {
    return NO;
}

Example implementations

I suggest that you either have an array of all the views in the order you want them to appear or use the tag property if you don't use it for anything else. The implementation of the protocol becomes super simple.

Array of elements

I'm assuming that you have an array called accessibleElements that store the elements in the correct order.

- (NSInteger)accessibilityElementCount {
    return self.accessibleElements.count;
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
    return self.accessibleElements[index]; 
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
    return [self.accessibleElements indexOfObject:element];
}

Tagged elements

I'm assuming that your subviews are tagged continuously from 0 up to the number of subviews.

- (NSInteger)accessibilityElementCount {
    return self.subviews.count;
}

- (id)accessibilityElementAtIndex:(NSInteger)index {
    // Not that self should have a tag<0 or tag>count otherwise it will 
    // return itself for that tag instead of the element you want it to.
    return [self viewWithTag:index]; 
}

- (NSInteger)indexOfAccessibilityElement:(id)element {
    return ((UIView *)element).tag;
}
多情癖 2024-12-05 10:00:33

在某些情况下,在一项上设置 UIAccessibilityTraitSummaryElement 可以实现此目的。 (我的游戏似乎太动态了,这没有多大帮助。)

In some cases, setting UIAccessibilityTraitSummaryElement on one item can do this. (My game seems too dynamic for this to help much.)

千柳 2024-12-05 10:00:33

Swift 5 您可以在 accessibilityElements 属性中指定元素的顺序

self.accessibilityElements = [lable1, label2, label2].compactMap {$0}

,用于指定 CollectionView 单元格的顺序。

 // MARK: collection view accessibility order
    override func accessibilityElementCount() -> Int {
        return numberOfItemInSection()// specify your items count
    }

    override func accessibilityElement(at index: Int) -> Any? {
        return collectionView.cellForItem(at: IndexPath(item: index, section: 0))
    }

Swift 5 You can specify the order of element in accessibilityElements property

self.accessibilityElements = [lable1, label2, label2].compactMap {$0}

For specifying the order of CollectionView cells.

 // MARK: collection view accessibility order
    override func accessibilityElementCount() -> Int {
        return numberOfItemInSection()// specify your items count
    }

    override func accessibilityElement(at index: Int) -> Any? {
        return collectionView.cellForItem(at: IndexPath(item: index, section: 0))
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文