ios - 更改控制中心(远程命令中心)中的辅助功能标签

标签 ios swift voiceover uiaccessibility mpremotecommandcenter

我有一个简单的应用程序可以播放广播电台。我添加了一个 MPRemoteCommandCenter 让用户通过控制中心控制音频。 一切正常。

但是,我想更改他们的辅助功能标签。但这是事情无法按预期工作的部分。

我已经按如下方式设置了我的 remoteCommandCenter:

let remoteCommandCenter = MPRemoteCommandCenter.shared()

然后,我添加了控件和处理程序:

remoteCommandCenter.playCommand.isEnabled = true
remoteCommandCenter.playCommand.addTarget(self, action: #selector(ExternalPlaybackController.handleExternalPlayPauseCommandEvent(_:)))

然后,我想添加一些可访问性标签:

remoteCommandCenter.playCommand.accessibilityLabel = "Play radio"

这是行不通的。如果我调试代码,编译器将执行该行。我做错了什么? 您甚至可以更改 remoteCommandCenter 的辅助功能标签吗?

最佳答案

Can you even change the accessibility labels of the remoteCommandCenter?

我从未使用过这种组件,但我认为它会被 VoiceOver 忽略,因为屏幕阅读器不会将其识别为辅助功能元素。

在我看来,您的代码编译没有问题,因为您的辅助功能属性属于 UIAccessibility 非正式协议(protocol),这意味着它被很好地识别为代码。
但是,它不会被 VoiceOver 解释为要读出的信息,因为您的元素不是一种 UIKit 控件。

我建议创建一个UIAccessibilityElement 用于您的 playCommand,以便根据需要自定义其行为 ⟹ Apple doc状态:

The UIAccessibility informal protocol is also implemented by the UIAccessibilityElement class, which represents custom user interface objects. If you create a completely custom UIView subclass, you might need to create an instance of UIAccessibilityElement to represent it. In this case, you would support all the UIAccessibility properties to correctly set and return the accessibility element’s properties.

关于ios - 更改控制中心(远程命令中心)中的辅助功能标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59028852/

相关文章:

ios - 防止 leftBarButtonItem 导航项显示警报

ios - 如何判断我的 Newsstand Atom Feed 是否会被处理?

ios - 我的 IBAction 中的 NSDictionary 变为零

swift - 理解 RealmSwift 中的平等

iOS 画圈

ios - 如何在数据库中存储数据(sqlite)

swift - 将 AWS DynamoDB 代码更新到 Swift 3 会导致错误

ios - 作为辅助功能元素的 VoiceOver 父 View 和 subview

html - 更改屏幕阅读器自定义无序列表字符的标签

ionic3 - 覆盖 ionic3 ionic 图标的 aria-label