进入后台时如何争取时间完全关闭 UIAlertView?

发布于 2024-10-11 22:28:58 字数 298 浏览 3 评论 0原文

我弹出一个 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 技术交流群。

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

发布评论

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

评论(3

世界和平 2024-10-18 22:28:58

您应该调用 - (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.

极致的悲 2024-10-18 22:28:58

我听说过这种情况发生——背景屏幕截图发生在触发背景的动画中间。

您可以使用 [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.

梅窗月明清似水 2024-10-18 22:28:58

以防万一其他人正在寻找对我有用的代码,这里是:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) { // Ok button
        // URL to be opened
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", [self phoneNumber]]];

        [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
        [[UIApplication sharedApplication] openURL:url];
    }
}

Just in case anyone else is looking for the code that worked for me, here it is:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) { // Ok button
        // URL to be opened
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", [self phoneNumber]]];

        [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
        [[UIApplication sharedApplication] openURL:url];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文