In this episode we're going take the animation you've been working on, export it as a custom UIButton and integrate it into a pre-existing iOS app! Integration like this is easy, which is great because it not only shows the power of Flow, but also makes the tutorial fairly short!
Through the last four episodes you’ve created an animation, and exported it to code. This time, however, we’re going to export it using a awesome option which wraps your animation in a UIButton so that it can be dropped right into an actual app.
This step starts at 0:08
The custom button export for iOS is a little different from the standard iOS option. First, selecting the button will play your button forward and deselecting will play it backwards.
This step starts at 0:45
Yes, that’s right. It’s possible for you to play your animations in reverse.
Aside from that, there’s a couple of files that set this option apart.
ToggleButton.swift
is a subclass of UIButton
that can handle animations from Flow.LikeTimelineButton.swift
is a subclass of ToggleButton
that handles your specific animation.Then, your animation’s playback is tied to a user clicking the button in the simulator.
This is a sample app, designed to be similar to what you might find out there in the real world (i.e. from both design and software perspectives).
This step starts at 1:37
This is what the app looks like in the simulator.
As you can see it has a card layout, and internally is structured using standard iOS programming approaches.
Now it’s time to integrate our exported button into the Flowcase app.
This step starts at 2:10
First, we need to copy a few files from our exported project into Flowcase.
This step starts at 2:21
We’ll do the same steps as before, but this time for your animation code.
This step starts at 3:03
In Flowcase, the current heart button is a UIButton. What we want to do it change it to the custom one we just ported over.
This step starts at 3:56
Flowcase uses a UICollectionView to manage displaying the cards, and this class relies on the FeedCell class to layout individual cards. We need to modify this class.
This step starts at 5:02
class FeedCell: UICollectionViewCell, ToggleButtonDelegate {
@IBOutlet weak var likeButton: LikeButtonTimelineButton!
likeButton.delegate = self
func createButtonTargets() {
webButton.addTarget(self, action: #selector(launchWeb(sender:)), for: UIControl.Event.touchUpInside)
}
func didToggle(sender: ToggleButton) {
data.liked = sender.isSelected
delegate.likeStatusChanged(cell: self)
}
toggleLikeButton(sender: UIButton)
method, including the @objc
above it.Done.
Now your project has a new custom button in it that plays the animation you made in Flow.
Check out the animation in the final app at: 7:03
Even though we had to do a little bit of code work, the effort to get an animation into something that’s working is nigh on zero.
Go show your devs how easy this is!
You’ve successfully gotten through our onboarding series. If you’ve followed along, not only have you learned to use Flow, but also these critical ideas:
We are planning to add a couple of advanced tutorials around this series, so stay tuned for them.
result(s) found for “”.