开发者

Overlay view on top of keyWindow quickly disappear (iOS)

When starting, my app checks for an update. If it is available, I try to put an overlay view on top of each other with this instruction:

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

The overlay view appears but quickly disappears, while I want to remove it when the update process ends. Instead, if I add the overlay view as a subview of the current view, the overlay view stays on top until the update process finishes.

I have to put the overlay view on top of keyWindows because my app has a tab bar, so if I put the overlay view on top of the current view, the overlay view will disappear if the user tap on another item in the tab bar.

May be due to the fact I moved the check for an update in a separate task with NSInvocation? Here is my relevant code:

[in viewDidLoad]

    NSOperationQueue *queue = [NSOperationQueue new];

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

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

[in checkForUpdate]

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

[in doUpdate]

UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Update" message:@"Downl开发者_运维百科oad the latest version of...?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

[alertView show];
[alertView release];

[in 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;
}

[in connectionDidFinishLoading]

[overlay removeFromSuperview];


I solved the problem adding the overlay to the tabbarViewController's view:

[self.tabBarController.view addSubview:overlay];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜