我可以在显示UIAlertView时收到消息

Bon*_*nny 2 iphone notifications uialertview

我想在系统显示UIAlertView时收到消息,这样我就可以暂停游戏了.

谁知道怎么弄明白?

UIAlertView不受我自己的控制.

小智 7

系统警报通常以其自身显示UIWindow.安装处理程序UIWindowDidBecomeVisibleNotificationUIWindowDidBecomeHiddenNotification通知以跟踪何时UIWindow分别变为可见和隐藏:

 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(aWindowBecameVisible:)
                                              name:UIWindowDidBecomeVisibleNotification
                                            object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self
                                          selector:@selector(aWindowBecameHidden:)
                                              name:UIWindowDidBecomeHiddenNotification
                                            object:nil];
Run Code Online (Sandbox Code Playgroud)

在处理程序中,UIWindowobject通知的属性中获取该更改状态:

- (void)aWindowBecameVisible:(NSNotification *)notification
{
    UIWindow *theWindow = [notification object];
    NSLog(@"Window just shown: %@", theWindow);
}

- (void)aWindowBecameHidden:(NSNotification *)notification
{
    UIWindow *theWindow = [notification object];
    NSLog(@"Window just hidden: %@", theWindow);
}
Run Code Online (Sandbox Code Playgroud)

最后,检查theWindow包含类型的子视图UIAlertView.