Skip to content
UIViewController class providing interactive & dynamic splash screens
Branch: master
Clone or download
Latest commit b9f22d4 Dec 25, 2014
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example Add one passing test for Travis. Oct 24, 2014
Pod Fixup file hierarchy, podfile, etc. Oct 24, 2014
.gitignore Initial commit Oct 24, 2014
.travis.yml Update .travis.yml to workaround xctool issue with Xcode6 and iOS8 Oct 24, 2014
LICENSE Initial commit Oct 23, 2014
LaunchScreen.podspec Version 1.0.0 Oct 24, 2014
README.md Update README.md Dec 24, 2014

README.md

LaunchScreen

CI Status Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

See below for how to integrate LaunchScreen into your app.

Requirements

This class, and the associated example, take advantage of Xcode 6's ability to use a Launch Screen storyboard rather than a set of Default images. It relies on a new Info.plist key UILaunchStoryboardName.

Motivation

Although Apple recommends against so called "splash" screens that show anything other than an app's initial, content-free chrome, it is common practice for apps to show a splash screen with some kind of graphic, perhaps animated, and often with some kind of indication that something is happening (e.g. an activity indicator spinning away).

Traditionally, to provide any kind of overlaid, long showing launch screen, you had to instantiate a view, fill it with something, display it over your initial view, then remove it. The mechanics of this are not complicated, but the hitch is when the "something" you want to fill this view with is not just a solid color. Here's where you start having many different versions and sizes of "Default.png" (with the lengthy list of names for different devices and screen sizes). With the introduction of the iPhone 6 and 6+, this nightmare expanded.

Enter Launch Screen XIBs made available with Xcode 6. These XIBs let you layout an initial screen that the system will display while it loads your app. You can use just about any UIKit element, including an activity indicator if you wanted to (but you'd have no way to control it programatically), and you can arrange everything using Auto Layout. So the need for multiple "Default" images is basically eliminated.

Why can't we use that XIB file programatically? It's just a UIView with other UIKit elements inside it. And, there's no reason we can't load it up and even add UIKit elements to the view dynamically. The trick, however, is that we're not going to affect what the system displays straight from the XIB. Instead, we're going to instantiate the XIB, insert its view into the view of another UIViewController from our storyboard, and manipulate that.

The trick that allows this to work for all screen sizes (and we're assuming you are using Size Classes in your storyboard) is that you must include in your storyboard a UIViewController whose class is LaunchScreenViewController. You must give this scene a storyboard identifier. There are two init methods; one assumes a storyboard id of LaunchScreenViewController, the other takes the id as a parameter if you'd prefer to use another id. By having a scene in your storyboard, and by using size classes, you are gauranteed that your Launch Screen XIB's view will be sized up or down as needed to fill the screen.

Installation

LaunchScreen is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "LaunchScreen"

Integration

Once you have LaunchScreen installed, using it is quite simple.

  • You'll need to be using a XIB for your launch screen.

  • Add the .h file appropriately whereever you are planning to manipulate and display a custom splash screen:

#import "LaunchScreenController.h"
  • Drag a UIViewController to your storyboard.

    • Set its class to LaunchScreenViewController
    • Set its storyboard identifier to LaunchScreenViewController
  • Instantiate a LaunchScrenViewController

LaunchScreenViewController *launchScreenVC = [[LaunchScreenViewController alloc] initFromStoryboard:self.storyboard];
  • You can take a snapshot of the rendered view:
UIImage *snapshot = [launchScreenVC snapshot];
  • You can add elements to the LaunchScreenViewControlelr's view and insert the view into your view hierarchy:
UIActivityIndicatorView *spinner = ...;
UIView *view = launchScreenVC.view;
[view addSubview:spinner];
...
[self.view addSubview:view];
[UIView animateWithDuration:1.0
                      delay:2.0
                    options:0
                 animations:^{
                    v.alpha = 0.0;
                 } completion:^(BOOL finished) {
                    [v removeFromSuperview];
                 }
];

Contributing

You know the drill: Fork, modify, create pull requests.

Author

Mark H. Granoff ~ @granoff / @hawkimedia

License

LaunchScreen is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.