【问题标题】:Overlay view on top of keyWindow quickly disappear (iOS)keyWindow 顶部的覆盖视图快速消失(iOS)
【发布时间】:2011-09-14 12:40:01
【问题描述】:

启动时,我的应用会检查更新。如果可用,我会尝试使用此指令将叠加视图置于彼此之上:

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

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

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

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

[在 viewDidLoad 中]

    NSOperationQueue *queue = [NSOperationQueue new];

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

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

[检查更新]

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

[在更新中]

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];

【问题讨论】:

    标签: ios uiview overlay


    【解决方案1】:

    我解决了将叠加层添加到 tabbarViewController 的视图的问题:

    [self.tabBarController.view addSubview:overlay];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-13
      • 1970-01-01
      相关资源
      最近更新 更多