显示 UIAlertView 时可以收到消息吗

发布于 2024-11-19 08:35:18 字数 94 浏览 0 评论 0原文

我想在系统显示 UIAlertView 时收到消息,以便我可以暂停游戏。

有人知道如何弄清楚吗?

UIAlertView不是由我自己控制的。

I want to get message when system show UIAlertView so I can pause my game.

Anyone know how to figure out that?

The UIAlertView is not controlled by myself.

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

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

发布评论

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

评论(4

意中人 2024-11-26 08:35:18

系统警报通常显示在其自己的 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];

在处理程序中,获取 UIWindow 从通知的 object 属性更改状态:

- (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);
}

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

A system alert is normally displayed in its own UIWindow. Install handlers for the UIWindowDidBecomeVisibleNotification and UIWindowDidBecomeHiddenNotification notifications to track when a UIWindow becomes visible and hidden respectively:

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

In the handlers, grab the UIWindow that changes state from the object property of the notification:

- (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);
}

Finally, check that theWindow contains a subview of type UIAlertView.

吻安 2024-11-26 08:35:18

应用程序委托的 applicationWillResignActive: 将在中断时调用。您可以在那里处理暂停,甚至可以收听 UIApplicationWillResignActiveNotification 在视图控制器中并在那里暂停游戏。

您可以查看这部分< iOS 应用程序指南的 /code>详细介绍了应用程序的生命周期和状态转换。

Application delegate's applicationWillResignActive: will be called on interrupts. You can handle the pause there or you can even listen to the UIApplicationWillResignActiveNotification in your view controller and pause the game there.

You can look at this part of the iOS Application Guide that details the life cycle of the application and state transitions.

最后的乘客 2024-11-26 08:35:18

如果您的 UIAlertView 来自第三方应用程序(而不是您的应用程序),那么您可以实现以下委托方法来暂停和恢复游戏。

暂停游戏

- (void)applicationWillResignActive:(UIApplication *)application {
}

恢复游戏

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

例如,如果您收到电话或短信,您可以使用上面的委托来暂停/恢复游戏。

If your UIAlertView is from Third party app (not from your app) then you can implement below delegate methods to pause and resume game.

To Pause game

- (void)applicationWillResignActive:(UIApplication *)application {
}

To Resume game

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

For example if you receive call or SMS you can use above delegate to pause/resume game.

情话墙 2024-11-26 08:35:18

只要这样做:

- (void)applicationWillResignActive:(UIApplication *)application {
//pause
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
//resume
}

Just make this:

- (void)applicationWillResignActive:(UIApplication *)application {
//pause
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
//resume
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文