Is there any way to catch the [VoiceOver - ON/OFF] event in my application?
I need to make my menu behave differently in two cases, using voiceover and normal way.
UIAccessibilityIsVoiceOverRunning()
BOOL
YES
如果它正在运行,则返回 a 。这是 iOS 4 及更高版本。
如果您需要它作为通知,UIAccessibilityVoiceOverStatusChanged
(也是 4.0+)。
在您的应用委托的applicationDidFinishLaunching:
方法中,订阅 VoiceOver 状态更改,如下所示:
// subscribing to VoiceOver change notification:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(didChangeVoiceOverSetting:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
然后做任何你需要做的事情。在我的应用程序中,我在代码的 viewDidLoad 方法中设置了大量可访问性代码,因此最简单的方法是在 VoiceOver 更改时使应用程序崩溃并允许重新初始化所有内容:
- (void)didChangeVoiceOverSetting:(NSNotification *)dictionary {
// intentionally crashing the app if VoiceOver is changed
assert(false);
}