iphone - UIApplication 的 "windows"值上的 KVO?

标签 iphone uikit

以下内容不起作用:

[[UIApplication sharedApplication] addObserver:self forKeyPath:@"windows"
   options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
   context:NULL];

与此同时,在观察者端:

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
  NSLog(@"never reached!");
}

有什么线索吗?

注意我的 super 目标是在显示(系统生成的)UIAlertView 时收到通知。

最佳答案

self 回答...

检测何时显示任意 UIAlertView 的正确方法是使用 NSNotificationCenter:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeVisible:) name:UIWindowDidBecomeVisibleNotification object:nil];

然后,在里面:

- (void) windowDidBecomeVisible:(NSNotification*)notification {}

检查有问题的 UIWindow(可通过 notification.object 访问)是否包含作为 UIAlertView 实例的 subview

关于iphone - UIApplication 的 "windows"值上的 KVO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2847649/

相关文章:

ios - iOS 13 上未调用supportedInterfaceOrientations

iphone - NSString 文本像素长度

iphone - 在 iPad (iOS 7) 上运行 iPhone 应用程序时,scalesPageToFit 无法正常工作

iphone - Xcode 4.5.1 iOS5/5.1 IBAction 不工作。在 iOS6 中很好

iphone - 获取iPhone照片曝光信息

带有 Popover 的 iOS Segues 具有不良的默认行为

swift - 如何使用 UIPickerView 确定 UITextField 的值?

iphone - UIImagePicker Controller : How do I add button and select photo

ios - xcode 7 json 总是在 Objective C 中显示错误

ios - iPhone X home 指示灯调光/不调光