辅助功能-iOS Voiceover状态

我正在尝试将辅助功能添加到已经开发的iOS应用中。

如果iPhone的辅助功能菜单中的VoiceOver选项处于打开状态,我希望它们显示几个UI功能(例如按钮),而如果禁用Voiceover,则不显示它们。

有没有办法检查画外音选项是否打开?

Arash asked 2019-10-09T17:39:14Z
4个解决方案
103 votes
BOOL UIAccessibilityIsVoiceOverRunning();
David Dunham answered 2019-10-09T17:39:18Z
30 votes

在ViewDIdLoad中

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(voiceOverStatusChanged)
                                             name:UIAccessibilityVoiceOverStatusChanged
                                           object:nil];


- (void)voiceOverStatusChanged
{
    if(!UIAccessibilityIsVoiceOverRunning())
    {
        //do your changes
    }
}
Rakesh iOS Dev answered 2019-10-09T17:39:41Z
3 votes

对于Swift 4.2,您可以检查UIKit提供的以下布尔值:

UIAccessibility.isVoiceOverRunning

Lucas P. answered 2019-10-09T17:40:11Z
3 votes

自iOS11起,作为所有先前正确答案的补充,新使用的通知名称为:

  • UIAccessibility.voiceOverStatusDidChangeNotification(SWIFT <4.2)。
  • UIAccessibility.voiceOverStatusDidChangeNotification(ObjC)。

...而UIAccessibility.voiceOverStatusDidChangeNotification已弃用。

编辑SWIFT 4.2 ==> UIAccessibility.voiceOverStatusDidChangeNotification

XLE_22 answered 2019-10-09T17:41:00Z
translate from https://stackoverflow.com:/questions/8827951/ios-voiceover-status