开发者

How To Get UIAccessibilityVoiceOverStatusChanged Notification

开发者 https://www.devze.com 2023-02-05 12:25 出处:网络
How to implement to get UIAccessibilityVoiceOverStatusChanged Notification? I tried like below 开发者_StackOverflow社区but nothing happens :

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.");
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消