打开自定义UITableViewCell时在溢出菜单中显示/隐藏辅助功能元素 [英] Showing / hiding accessibility elements in an overflow menu when opening a custom UITableViewCell

查看:117
本文介绍了打开自定义UITableViewCell时在溢出菜单中显示/隐藏辅助功能元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自定义 UITableViewCell 类中实现可访问性。我有一个相当简单的溢出菜单,里面有几个按钮,这些按钮一直被隐藏,直到按下省略号按钮才能滑动打开并关闭溢出。

I’m implementing accessibility in a custom UITableViewCell class. I have a fairly simple overflow menu with a couple of buttons inside it, which are hidden until an ellipsis button is pushed that slides open and closes the overflow.

在我的单元格中初始化程序,我将我的 overflowContainer accessibilityElementsHidden 设置为 YES

In my cell's initialiser I’m setting the accessibilityElementsHidden of my overflowContainer to YES. This seems to work, when scrolling through using VoiceOver, those views are skipped.

然后,当打开单元格时,在的完成处理程序中,这似乎起作用。 UIView 动画,我将相同的 overflowContainer 的相同的 accessibilityElementsHidden 设置为NO。

Then, when opening the cell, in the completion handler of the UIView animation, I set that same accessibilityElementsHidden of the same overflowContainer to NO. This doesn’t seem to have any effect, those elements are still skipped.

我也尝试过发布 UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,nil)在更改 accessibilityElementsHidden BOOL 之前/之后/但是,这似乎也没有作用

I’ve also tried posting UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil) before / after / when changing the accessibilityElementsHidden BOOL, but this also appears to have no effect on the situation.

基本上我想在几个上切换 accessibilityElementsHidden UIView 实例在特定位置。有人可以让我知道我可能在做什么错吗?

Basically I’d like to toggle accessibilityElementsHidden on a couple of UIView instances at a specific point. Could anyone let me know what I may be doing wrong?

这里是溢出打开时我触发的代码:

Here’s the code I fire when the overflow opens:

- (void)cellOverflowDidShow:(MyCell *)cell
{
    self.overflowContainer.isAccessibilityElement = YES;
    self.firstButton.isAccessibilityElement = YES;
    self.secondButton.isAccessibilityElement = YES;
    self.thirdButton.isAccessibilityElement = YES;
    UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.firstButton);
}

在关闭单元格时,我反其道而行之(将所有值设置为并再次发布通知)。并且在初始化单元格时,我所要做的就是:

I fire the opposite when closing the cell (set all to NO and post notification again). And when initializing the cell, all I set is:

self.overflowContainer.isAccessibilityElement = NO;

完全不知道为什么它不应该工作,看来我在正确地完成所有工作100% 。如果我没有在初始化程序中设置该行,则所有按钮都将显示(始终)。因此,似乎第一个调用有效,无论是 YES 还是 NO ,但随后的所有调用都将被忽略。 / p>

Absolutely no idea why it shouldn’t be working, it appears I’m doing everything 100% correctly. If I don’t set the line in the initializer, the buttons all appear accessible (all the time). So it appears that the first call, be it YES or NO, works, but any subsequent ones are ignored.

推荐答案

在可见状态下,您将溢出容器声明为可访问性元素。因此,VoiceOver将允许用户集中精力而不是导航子元素。与其切换是否为辅助功能元素,不如将 self.overflowContainer.isAccessibilityElement 设置为 NO 并切换其可访问性子元素,firstButton,secondButton和thirdButton。

In the visible state, you declare the overflow container to be an accessibility element. Thus, VoiceOver will allow the user to focus it rather than navigate child elements. Instead of toggling whether it's an accessibility element, keep self.overflowContainer.isAccessibilityElement set to NO and toggle the accessibility of its children, firstButton, secondButton, and thirdButton.

设置子元素可访问性的简写是 accessibilityElementsHidden 。尝试在显示视图时将 self.overflowContainer.accessibilityElementsHidden 设置为 NO YES 消失。

A shorthand for setting the accessibility of child elements is accessibilityElementsHidden. Try setting self.overflowContainer.accessibilityElementsHidden to NO when the view appears and YES when it disappears.

无论如何,您可能仍需要触发布局更改通知。

You may still need to trigger a layout change notification, regardless.

这篇关于打开自定义UITableViewCell时在溢出菜单中显示/隐藏辅助功能元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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