如何实现获取UIAccessibilityVoiceOverStatusChanged
通知?
我尝试过如下但没有任何反应:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
这看起来很合理,除了可能是对象:self应该是对象:nil?另一件事是确保你的签名是正确的:
- (void)voiceOverStatusChanged: (NSNotification *)notification;
我想你可能会尝试使用正确的选择器签名在awakeFromNib方法中添加观察者。
这样的东西会起作用
- (void)awakeFromNib {
[super awakeFromNib];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(voiceOverChanged)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
[self voiceOverChanged];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIAccessibilityVoiceOverStatusChanged object:nil];
}
- (void)voiceOverChanged {
// Your actions here
}
您可以使用代码获取UIAccessibilityVoiceOverStatusChanged通知
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(didChangeVoiceOverStatus:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
}
- (void)didChangeVoiceOverStatus:(NSNotification *)notification {
if (UIAccessibilityIsVoiceOverRunning()) {
NSLog(@"VoiceOver is ON.");
} else {
NSLog(@"VoiceOver is OFF.");
}
}