如何获取 UIAccessibilityVoiceOverStatusChanged 通知

发布于 2024-10-13 01:50:17 字数 287 浏览 2 评论 0原文

如何实现获取UIAccessibilityVoiceOverStatusChanged通知?

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

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

How to implement to get UIAccessibilityVoiceOverStatusChanged Notification?

I tried like below but nothing happens :

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰魂雪魄 2024-10-20 01:50:18

这看起来很合理,但也许 object:self 应该是 object:nil ?
另一件事是确保您的签名正确:

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

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;
海夕 2024-10-20 01:50:18

我认为您可以尝试使用正确的选择器签名在 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
}

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
}
落花随流水 2024-10-20 01:50:18

您可以通过代码获取 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.");
        }
    }

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.");
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文