进入后台时如何争取时间完全关闭 UIAlertView?
我弹出一个 UIAlertView
询问用户是否确实要打开 URL。如果他们选择“是”,我的应用程序会立即打开 URL 并发送到后台。当用户重新打开我的应用程序(使用多任务处理)时,警报视图尚未完全消失并且处于半透明状态。据推测,多任务处理中使用的屏幕截图是在警报视图完全消失之前拍摄的,但就在它开始消失之后。
如何为我的应用程序提供完全消除警报视图所需的额外时间?看来我应该在 -applicationDidEnterBackground:
中做一些事情,或者在视图控制器中监听等效的通知,但我不确定最好的方法。
I pop up a UIAlertView
to ask the user if they really want to open a URL. If they choose "Yes" my app immediately opens the URL and is sent to the background. When the user reopens my app (with multitasking) the alert view hasn't disappeared completely and is in a half-transparent state. Presumably the screenshot used in multitasking was taken before the alert view completely disappeared, but just after it began to fade away.
How can I give my app the extra second it needs to completely dismiss the alert view? It seems like I should do something in -applicationDidEnterBackground:
or listen in the view controller for the equivalent notification but I'm not sure about the best approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该调用
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndexAnimated:(BOOL)animated
。在 iOS 4 中,当应用程序移至后台时,警报视图不会自动消失。You should call
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
. In iOS 4 alert views are not dismissed automatically when an app moves to the background.我听说过这种情况发生——背景屏幕截图发生在触发背景的动画中间。
您可以使用
[self PerformSelector: withObject: afterDelay:]
在警报解除和应用程序后台运行之间插入一段时间。withDelay
是一个浮点数,接受秒的几分之一,因此您可以很好地对其进行微调。I've heard of this happening--the backgrounding screenshot happens in the middle of the animation of the thing that triggered the backgrounding.
You could use
[self performSelector: withObject: afterDelay:]
to insert a bit of time between the dismissal of the alert and the backgrounding of the app.withDelay
is a float and accepts fractions of seconds, so you can fine tune it pretty nicely.以防万一其他人正在寻找对我有用的代码,这里是:
Just in case anyone else is looking for the code that worked for me, here it is: