0

I've got the following code fragment (for illustration purpose):

- (IBAction)buttonPress:(id)sender {
    UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    activityIndicator.center = overlayView.center;
    [overlayView addSubview:activityIndicator];
    [self.navigationController.view addSubview:overlayView];
    //[self.navigationController.view bringSubviewToFront:overlayView];
    [activityIndicator startAnimating];

    sleep(10);

    //[overlayView removeFromSuperview];
}

I wonder why the overlay view is only displayed after the method returns...

Andrew
  • 197
  • 2
  • 3
  • 16

1 Answers1

0

I guess it's because sleep(10) blocks the main thread which is responsible for performing UI related activities, such as drawing on screen.

Remove the sleep(10) line and should work fine.

Here's on link to SO in case you're interested how to use delays in coca-touch:
Adding delay between execution of two following lines

Community
  • 1
  • 1
Andrej
  • 7,266
  • 4
  • 38
  • 57