ios - keyWindow 顶部的叠加 View 快速消失(iOS)

标签 ios uiview overlay

启动时,我的应用会检查更新。如果可用,我会尝试使用以下指令将叠加 View 相互叠加:

[[[UIApplication sharedApplication] keyWindow] addSubview:overlay];

叠加 View 出现但很快消失,而我想在更新过程结束时将其删除。相反,如果我将叠加 View 添加为当前 View 的 subview ,则叠加 View 将保持在顶部,直到更新过程完成。

我必须将覆盖 View 放在 keyWindows 之上,因为我的应用程序有一个标签栏,所以如果我将覆盖 View 放在当前 View 的顶部,如果用户点击另一个项目,覆盖 View 将消失标签栏。

可能是因为我使用 NSInvocation 在单独的任务中移动了更新检查?这是我的相关代码:

[在 viewDidLoad 中]

    NSOperationQueue *queue = [NSOperationQueue new];

    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(checkForUpdate) object:nil];

    [queue addOperation:operation];
    [operation release];

[在 checkForUpdate 中]

    if (![localVersion isEqualToString:remoteVersion])
    {
        [self performSelectorOnMainThread:@selector(doUpdate) withObject:nil waitUntilDone:NO];
    }

[在 doUpdate 中]

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Update" message:@"Download the latest version of...?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

[alertView show];
[alertView release];

[在 willDismissWithButtonIndex]

if (buttonIndex == 1)
{
    CGRect overlayFrame = [[UIApplication sharedApplication] keyWindow].bounds;
    overlay = [[UIView alloc] initWithFrame:overlayFrame];
    overlay.backgroundColor = [UIColor blackColor];
    overlay.alpha = 0.7;

    // Do other staff...

    [[[UIApplication sharedApplication] keyWindow] addSubview:overlay];

    NSURL *url = [NSURL URLWithString:@"http:www.testserver.com/test/UpdatePack.zip"];
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:300.0];

    connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    connection = nil;
}

[在connectionDidFinishLoading]

[overlay removeFromSuperview];

最佳答案

我解决了将叠加层添加到 tabbarViewController 的 View 中的问题:

[self.tabBarController.view addSubview:overlay];

关于ios - keyWindow 顶部的叠加 View 快速消失(iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7416475/

相关文章:

ios - 如何通过 Mailcore/Libetpan 设置电子邮件 IMAP SEEN 标志

objective-c - 如何将 UTF-8 字符添加到 NSString?

ios - Swift/如何使 MFMailComposeViewController 消失

iOS 应用程序启动为黑色 View

swift - UICollectionView 中的 ScrollToItem 没有发生任何事情

objective-c - UIView animateWithDuration : duration: animations: completion: seems to have a default transition?

ios - Iphone 4 和 Iphone 5 中的 UIView 问题

自定义文本字段上的 swiftui ios15 键盘回避问题

html - 如何在网站内叠加图像 (png)?

android - 如何在 Android 中的视频上渲染 Web Kit 内容?