1

UIAccessibilityVoiceOverStatusChanged通知を取得するために実装する方法は?

以下のように試しましたが、何も起こりません:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(notified:) name:UIAccessibilityVoiceOverStatusChanged object:self];
4

3 に答える 3

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.");
        }
    }
于 2017-01-04T04:15:38.927 に答える
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
}
于 2015-09-07T11:07:46.163 に答える
0

おそらく object:self が object:nil であるべきであることを除いて、それは合理的に見えますか? もう 1 つは、署名が正しいことを確認することです。

- (void)voiceOverStatusChanged: (NSNotification *)notification;
于 2012-01-20T03:11:29.883 に答える