我有兴趣以编程方式捕获应用程序中的 UI 更改,并认为 UIAccessibility
协议(protocol)可能会有所帮助。我找到了如何发布 UIAccessibilityLayoutChangedNotification
和 UIAccessibilityScreenChangedNotification
,但我不确定如何注册以接收这些通知。
我尝试过使用 NSNotificationCenter
,但 name
参数需要一个 string
,而上面的两个通知的类型为 >UIAccesibilityNotifications
这是一个 int
。
知道如何注册这些通知吗?
谢谢!
最佳答案
这是一个很好的问题!不幸的是,您无法在不影响正常行为的情况下收到这些“通知”。 (即“不,你不能”)
<小时/>如果你反汇编UIKit,你会发现UIAccessibilityPostNotification
是这样实现的:
static void (*__UIAccessibilityBroadcastCallback)(UIAccessibilityNotifications notification, id argument);
void UIAccessibilityPostNotification(UIAccessibilityNotifications notification, id argument) {
__UIAccessibilityBroadcastCallback (notification, argument);
}
这意味着这些辅助功能“通知”不是任何正常的通知。相反,它们只是内部回调函数的参数。回调函数的实现方式取决于您使用的辅助功能包。
您可以使用未记录 API _UIAccessibilitySetBroadcastCallback
将回调函数替换为您自己的回调函数:
void _UIAccessibilitySetBroadcastCallback(void (*replacement)(UIAccessibilityNotifications notification, id argument)) {
__UIAccessibilityBroadcastCallback = replacement;
}
但是,没有相应的“get”函数(甚至不是私有(private)的),因此一旦设置它,就无法再次通知原始监听器。
关于iphone - 如何在 iPhone 应用程序中接收 UIAccessibility 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2137172/