Prevent Splash Screen from showing after returning from background

前端 未结 5 1504
刺人心
刺人心 2020-12-16 17:00


I\'ve noticed something that happens in every app i develop. It\'s usually not a concern but in this specific app it would be great if i could \"fix\" it, if it\'s ev

5条回答
  •  抹茶落季
    2020-12-16 17:17

    Your code to display your splash screen should be in your appdelegate in the didFinishLaunchingWithOptions method. If it is then it only appears when your app actually starts up, not when it returns from the background.

    Use something like this (I know it uses the old animation code but I 'm sure you can update it to blocks if you need to)...

        splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
        splashView.image = [UIImage imageNamed:@"Default.png"];
    
        [myWindow addSubview:splashView];
        [myWindow bringSubviewToFront:splashView];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationDelegate:self]; 
        [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
        splashView.alpha = 0.0;
        [UIView commitAnimations];
    

    and then create a method called startupAnimationDone...

    - (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    
        [splashView removeFromSuperview];
    
        [splashView release];
    }
    

提交回复
热议问题