41

I'm quite a newbie in Cocoa, Objective-C and iOS development.

I'd like to implement a View that is just a splash screen and only last for a short time before routing to the main view. Do you have any idea on how I should implement that ? Any tutorials or code samples ? I have some with multiple views, but none with a timer to redirect to another one after a few seconds like I want to do.

Ozair Kafray
  • 13,351
  • 8
  • 59
  • 84
Patrice Cote
  • 3,572
  • 12
  • 43
  • 72

11 Answers11

40

See App Launch (Default) Images under the iOS Application Programming Guide.

It should also be noted Apple advised NOT abusing the launch image as a splash screen. Apple HIG

Espresso
  • 4,722
  • 1
  • 24
  • 33
  • 17
    but most famous apps do, don't they? http://www.appcoda.com/wp-content/uploads/2012/05/Sample-iOS-Splash-Screen.jpg – Tobias Jan 29 '13 at 17:25
  • 2
    @LordFlash Just because a large percentage of people do something does not necessarily make it the "right" way to do things:) That being said Apple is technically the only iOS App maker that doesn't need to enforce a brand identity but still :) – Daniel Galasko Oct 14 '14 at 15:40
32

You can easily implement your view on top of the main view but in your appDelegate. For example, if you want a splash image that fades out to the main view: (or a default image that seems to fade out: just put the same image on the splash screen and the default screen). This gives you also the right orientation as long as it is the main view's.

Just add it in your application:(UIApplication *)application didFinishLaunchingWithOptions: method:

 UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"your_default_image_or_another.png"]];
[[firstViewController view] addSubview:imageView];
[[firstViewController view] bringSubviewToFront:imageView];

// as usual
[self.window makeKeyAndVisible];

//now fade out splash image
[UIView transitionWithView:self.window duration:1.0f options:UIViewAnimationOptionTransitionNone animations:^(void){imageView.alpha=0.0f;} completion:^(BOOL finished){[imageView removeFromSuperview];}];
iBug
  • 2,334
  • 3
  • 32
  • 65
NightCoder
  • 1,049
  • 14
  • 22
  • 3
    I know that Apple and most users can't stand these delayed default images, but sometimes it's not up to us developers to decide! Anyway, ups to you for the first really clear answer to this question. – Mick Byrne Feb 16 '13 at 11:50
  • When I use the code mentioned above by NightCoder, I get the desired splash screen with fade out on the iPhone simulator, but the picture seems to be zoomed with factor 2: I only get the upper left quarter of my initial picture (= launch image), zoomed to full screen. The launch image is shown in correct size at startup, before the splash screen kicks in. Furthermore the splash screen doesn't seem to appear on the device, only on the simulator: when run on iPhone, it only displays the launch image. What's the cause and solution to both issues? – user1492198 Nov 11 '12 at 19:23
  • My issues have been solved: file extension was in upper case and I had to declare a frame and content mode. – user1492198 Nov 19 '12 at 20:48
  • 2
    Noob question, where do I get "firstViewController" from? – Ruben Martinez Jr. Jul 12 '14 at 18:10
12

As @Espresso posted link, I just wants to explain it to you.

If you just place an image named Default.png inside your project then it will be used for splash screen. However you can use different image name by explicitly specifying it in plist file.

Waqas Raja
  • 10,802
  • 4
  • 33
  • 38
11

I know I'm giving answer to almost one year old question, but it may help some one else-

I've just discovered that you can do this in XCode4! Which makes this a rather simple process now.

  1. Select your project in the navigation view
  2. under Targets select your application
  3. Select the Summary tab
  4. Scroll down and you'll see a place to add your splash images
  5. Right click on the boxes to Select File
Bharat
  • 2,987
  • 2
  • 32
  • 48
  • 2
    Actually a great way to do it! It even does the naming/renaming for you for the Retina display image. – bobobobo Apr 05 '13 at 17:23
6

The other answers are good but I'd like to add that for iPhone apps your Default.png should be 320x480 and for retina displays you should add Default@2x.png 640x960.

nylund
  • 1,105
  • 10
  • 15
4

In XCode 4, you can click on the Project Name (the parent in the hierarchy on the left).

Then in the Summary tab, under iPhone and iPad you will be able to select the Launch images for each form the file system.

Flaviu
  • 6,240
  • 4
  • 35
  • 33
3

To add splash screen just simply replace all the default images (likedefault@2x.png,....) with your splash image with the same default name (for all hardware display type) . To increase the duration of your splash screen , in appDelegate method

didFinishLaunchingWithOptions 

just sleep the main thread for the duration you want as:

[NSThread SleepForTimeInterval:(Your time interval)];

you can also use sleep(time interval) in

didFinishLaunchingWithOptions

sleep(3);
Rugmangathan
  • 3,186
  • 6
  • 33
  • 44
3

Having just had to fix this same problem myself, I thought I'd post an update.

I found that I had to set the Supported Interface Orientations in the Info.plist before it would work correctly.

I also found this article on iOSDeveloperTips.com to be pretty useful: Managing Multiple Launch Images

HaemEternal
  • 2,229
  • 6
  • 31
  • 50
2

You only have to add three images for iPhone, iPhone 5 and iPad named Default.png, Default-568h@2x.png and Default@2x.png. Now the clarity of the images depends on the size you are taking. You should take the standard sizes.

Ashutosh
  • 2,215
  • 14
  • 27
1

To add splash screen first add that image in your project and then add the following code to your AppDelegate method in the didFinishLaunching method

[NSThread SleepForTimeInterval:(Time interval)];
sma
  • 9,449
  • 8
  • 51
  • 80
Ashwin H
  • 695
  • 7
  • 24
0

Best solution for implementing splash screen on Storyboard Xcode Version 12.5.1 (12E507) in 4 steps your splash screen is done enter image description here

Hassan Kalhoro
  • 182
  • 2
  • 8