如何获取UIAccessibilityVoiceOverStatusChanged通知

问题描述 投票:1回答:3

如何实现获取UIAccessibilityVoiceOverStatusChanged通知?

我尝试过如下但没有任何反应:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
iphone ios nsnotificationcenter
3个回答
0
投票

这看起来很合理,除了可能是对象:self应该是对象:nil?另一件事是确保你的签名是正确的:

- (void)voiceOverStatusChanged: (NSNotification *)notification;

0
投票

我想你可能会尝试使用正确的选择器签名在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
}

0
投票

您可以使用代码获取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.");
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.