In this tutorial we will create an iOS launch screen animation with Flow and integrate it into an existing Xcode project.
First…
There are two main components to this project: a) a design file we’ll use to generate an iOS app, b) a flow file with an animation that we’ll use as the launch animation.
The file we’ll work with is a concept layout for a Travel app. In Sketch it looks like this:
We’ll use this to generate an Xcode project that will be our “mockup” application.
The other file we’ll use is a .flow file with a simple animation of the Flow wordmark.
We’ll dive into why this animation works in the next section.
In the .zip you just downloaded (link above if you missed it), there are a few other files:
Let’s create the Xcode project that we’ll use as our existing app, into which we will add a launch animation.
BarcelonaLayout.flow⌘⬆︎E to open the Export dialog windowConfigure next to the iOS optionBarcelona, then hit saveLet’s have a look at how the Xcode launch screen is set up.
UIImageViewFlowWordmark290x60Let’s dig into where you can find the actual asset.
Assets.xcassetsShow In Finderwordmark.pdf fileThe wordmark is just a pdf. You’ll notice that the wordmark.sketch file has an artboard that is the exact same dimensions as the pdf you just opened. We’ll use this fact to animate the launch screen.
When we were working on our export template, we generated the wordmark asset using the wordmark.sketch folder and included it in the launch screen of the exported xcode project.
The launch screen is a single flat / static layout. In Xcode / iOS you CANNOT animate the launch screen – in fact, you can’t even add any custom views to that storyboard.
When your app launches, it will fade from the launch screen to the first view of your app.
The trick to creating a launch screen animation is:
The animation's start state needs to be EXACTLY the same layout as the launch screen.
For this tutorial we’re a bit lucky – Flow already exports projects that have a launch screen with an asset – all we have to do is create the aniamation.
wordmark.flow⌘⬆︎E to open the Export dialog windowConfigure next to the iOS optionWordmark, then hit saveThe sketch file was designed so that it's starting position is identical to the exported launch screen. This is why it looks like we're animating the launch screen.
We want the animation to automatically trigger when the app launches.
SceneViewController.swiftNow the animation will trigger as soon as the view appears on the screen.
public override func viewDidAppear(_ animated: Bool) {
timeline.animate()
}
HIT PLAY!
Alright, it’s time to work some magic. The next few steps will integrate code from the wordmark.xcodeproj into the barcelona.xcodeproj, and at the end we’ll have added a launch animation to an iOS app!
First, we need to rename things otherwise we’ll get some decent clashes in Xcode. Do the following in wordmark.xcodeproj:
SceneViewController.swift to WordmarkViewController.swiftRefactor > RenameSceneViewController to WordmarkViewControllerSceneView.swift to WordmarkView.swiftRefactor > RenameSceneView to WordmarkViewBy default, Flow exports the main scene of an animation as a SceneView… Since we have 2 projects exported from Flow they will both have the same class name. So, without the steps we just completed, Xcode would yell at us if we tried to merge the two projects.
If Xcode throws an error while you're refactoring, try quitting Xcode.
Next, we need to rename things in barcelona.xcodeproj:
SceneViewController.swift to BarcelonaViewController.swiftBarcelonaViewController.swift select the name of the class SceneViewController then right-click and choose Refactor > RenameSceneViewController to BarcelonaViewControllerSceneView.swift to BarcelonaView.swiftBarcelonaView.swift select the name of the class SceneView then right-click and choose Refactor > RenameSceneView to BarcelonaViewWe don’t need to rename this project, per se, but it’s always nice to have clean code.
Now, we drag the three main wordmark files into the barcelona project.
WordmarkWordmarkView.swift, WordmarkTimeline.swift and WordmarkViewController.swift into the new group you created in the barcelona projectHit Play to make sure that the barcelona project compiles
To create our animation effect, we want our application to build a view controller that lives “in between” the LaunchScreen and our application’s primary view controller.
We do this in Interface Builder.
For those of you lovely creatures who aren't experienced with Xcode, please watch the video below to see where all the fields and things in Xcode are located.
Main.storyboard from the project navigator.WordmarkViewController in the identity inspector290 x 60WordmarkViewscene outlet to the view you just createdThe last step…
In the ViewDidAppear method, add a bit of code to make the whole method look like this…
public override func viewDidAppear(_ animated: Bool) {
timeline.animate()
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
self.showBarcelona()
}
}
The DispatchQueue nonsense tells the application to run the transition method one second after the animation begins (i.e. .now() + 1)
HIT PLAY
result(s) found for “”.