如何实现获取UIAccessibilityVoiceOverStatusChanged
通知?
我尝试如下,但没有任何反应:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
如何实现获取UIAccessibilityVoiceOverStatusChanged
通知?
我尝试如下,但没有任何反应:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
这看起来很合理,除了 object:self 应该是 object: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.");
}
}