显示 UIAlertView 时可以收到消息吗
我想在系统显示 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
系统警报通常显示在其自己的 UIWindow 中。为
UIWindowDidBecomeVisibleNotification
和UIWindowDidBecomeHiddenNotification
通知安装处理程序,以分别跟踪UIWindow
何时变得可见和隐藏:在处理程序中,获取
UIWindow
从通知的object
属性更改状态:最后,检查
theWindow
是否包含类型的子视图UIAlertView
。A system alert is normally displayed in its own
UIWindow
. Install handlers for theUIWindowDidBecomeVisibleNotification
andUIWindowDidBecomeHiddenNotification
notifications to track when aUIWindow
becomes visible and hidden respectively:In the handlers, grab the
UIWindow
that changes state from theobject
property of the notification:Finally, check that
theWindow
contains a subview of typeUIAlertView
.应用程序委托的
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 theUIApplicationWillResignActiveNotification
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.如果您的 UIAlertView 来自第三方应用程序(而不是您的应用程序),那么您可以实现以下委托方法来暂停和恢复游戏。
暂停游戏
恢复游戏
例如,如果您收到电话或短信,您可以使用上面的委托来暂停/恢复游戏。
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
To Resume game
For example if you receive call or SMS you can use above delegate to pause/resume game.
只要这样做:
Just make this: