Show activity indicator during application launch

后端 未结 4 1061
花落未央
花落未央 2020-12-21 07:13

I am trying to add an activity indicator during startup. I did have a launch image, but I\'d rather have just an indicator alone. I added the following to my app delegate, b

4条回答
  •  醉话见心
    2020-12-21 07:42

    Another solution is to let the launchimage load and when your ViewController loads at the viewDidLoad, use overlay + indicator on top of your view with alpha below 1:

    UIView *baseView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.view addSubview:baseView];
    [baseView setBackgroundColor:[UIColor blackColor]];
    baseView.userInteractionEnabled = NO;
    baseView.alpha = 0.4;
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
    indicator.center = self.view.center;
    [self.view addSubview:indicator];
    [indicator bringSubviewToFront:self.view];
    [indicator startAnimating];
    

    Now comes the fun part, use delegate to remove the indicator + overlay when all your background threads finish to load up and simple call a method via your delegate:

    - (void) onFinishLoading{
            [indicator stopAnimating];
            [baseView removeFromSuperview];
    }
    
    • In order to stopAnimation and removeFromSuperView you might want to make baseView and indicator property + @synthesize

提交回复
热议问题