How to use Default Splash Screen for Universal application?

1.9k views Asked by At

I have a universal application. In this application I set a introduction image as a splash screen. For iPhone I need to set a different image as splash screen and for iPad different image. When I'm using the below code it works for iphone but not for ipad.here is my code.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   [self copyDatabaseIfNeeded];
   [window addSubview:navigationController.view];
   [window makeKeyAndVisible];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    splashViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
    splashViewBg.image = [UIImage imageNamed:@"jamil.png"];
    //splashViewBg.contentMode = UIViewContentModeScaleAspectFill;
    [window addSubview:splashViewBg];

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
    splashView.image = [UIImage imageNamed:@"jamil.png"];
    //splashView.contentMode = UIViewContentModeScaleAspectFill;
    splashView.alpha = 0.0f;
}
else
{
    splashViewBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashViewBg.image = [UIImage imageNamed:@"defualt.png"];
    //splashViewBg.contentMode = UIViewContentModeScaleAspectFill;
    [window addSubview:splashViewBg];

    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"defualt.png"];
    //splashView.contentMode = UIViewContentModeScaleAspectFill;
    splashView.alpha = 0.0f;
}

[UIView beginAnimations:@"show" context:NULL];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
splashView.alpha = 1.0f;
[UIView commitAnimations];

[self performSelector:@selector(removeSplash) withObject:nil afterDelay:2.0];

[self performSelector:@selector(removeSplashBg) withObject:nil afterDelay:3.5];

return YES;
 }

 - (void) removeSplash {
   [UIView beginAnimations:@"hide" context:NULL];
   [UIView setAnimationDuration:1.0f];
   [UIView setAnimationCurve:UIViewAnimationCurveLinear];
   [UIView setAnimationDelegate:self];
   splashView.alpha = 0.0f;
  [UIView commitAnimations];
}

  - (void) removeSplashBg {
      [splashView removeFromSuperview];
      [splashViewBg removeFromSuperview];
}
1

There are 1 answers

0
melsam On BEST ANSWER

I know this doesn't directly answer your question, but Apple's guidelines specifically say NOT to use splash screen images. It is strongly discouraged, and may create a very poor, inconsistent experience for your users. If you must show a screen while the app is loading, you can do so without writing a single line of code. Just name the images Default.png and [email protected]. They will automatically be loaded and displayed as splash screens. See the documentation for "Launch Images".