是否可以将可访问性操作分配给UILabel? [英] Is it possible to assign an accessibility action to a UILabel?

查看:74
本文介绍了是否可以将可访问性操作分配给UILabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前用户界面中,某些标签旁边有一个帮助提示按钮,单击该按钮可解释标签所引用内容的详细信息。因此,VoiceOver将这两个项目标识为单独的可访问性项目。

In our current UI, next to certain labels, we have a help-tip button that when clicked, explains the details of what the label references. As such, VoiceOver identifies these two items as separate accessibility items.

但是,当使用可访问性时,我们希望我们可以在标签本身中做所有事情。这样,当标签聚焦时,用户将在这里帐户值,$ 20(accessibilityLabel),连按两次以获取帮助(accessibilityHint)

However, when using accessibility, we're hoping we can just do everything in the label itself. This way when the label gets focused, the user will here 'Account value, $20 (the accessibilityLabel), double-tap for help (the accessibilityHint)'

按钮,标签没有与之关联的动作,因此我不确定如何连线以实际触发指示我要执行操作的可访问性手势。

However, unlike a button, a label doesn't have an action associated with it so I'm not sure how to wire up actually triggering the accessibility gesture indicating I want to do something.

将所有标签转换为按钮的快捷方式,有什么方法可以监听标签上的可访问性操作方法?

Short of converting all of our labels over to buttons, is there any way to listen to the accessibility 'action' method on our labels?

我当前的解决方法是只能使帮助提示按钮可访问,然后将所有相关信息移至它们的可访问性属性,但这看起来像是代码异味,因为开发人员在更新代码时很容易错过它。

My current work-around is to make only the Help-tip buttons accessible, then move all the relevant information to their accessibility properties, but that seems like code smell as it's easy for a developer to miss that when updating the code.

推荐答案

在您的 UILabel 子类中,覆盖 accessi bilityActivate() 并实施双击操作:

In your UILabel subclass, override accessibilityActivate() and implement whatever double-tapping should do:

override func accessibilityActivate() -> Bool {
    // do things...
    return true
}

如果操作失败,则在这些情况下返回 false

If the action can fail, return false in those instances.

这篇关于是否可以将可访问性操作分配给UILabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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