How to implement to get UIAccessibilityVoiceOverStatusChanged
Notification?
I tried like below 开发者_StackOverflow社区but nothing happens :
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
That looks reasonable, except maybe object:self should be object:nil? The other thing is to be sure your signature is correct:
- (void)voiceOverStatusChanged: (NSNotification *)notification;
I think you might try adding the observer in the awakeFromNib method with the right selector signature.
Something like this will work
- (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
}
you can get the UIAccessibilityVoiceOverStatusChanged Notification with the code
- (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.");
}
}
精彩评论