启动时,我的应用会检查更新。如果可用,我会尝试使用以下指令将叠加 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/