Back to Ibanimatable

How to design and prototype custom transition animation and gesture interaction in Interface Builder with IBAnimatable

Documentation/Transitions.md

6.1.023.1 KB
Original Source

How to design and prototype custom transition animation and gesture interaction in Interface Builder with IBAnimatable

For most of the non-trivial apps, they may have more than one Scene (ViewController). In that case, we need to support navigation. Interface Builder is a great to prototype navigation like presenting or pushing another ViewController from current ViewController. To improve the user experiences, we can display transition animation when navigating from one scene to another. May 30th, 2016 as of this writing, out of the box, Interface Builder only supports a small set of transition animations for Present e.g. "Cover Vertical" and "Flip Horizontal". With IBAnimatable we can configure custom transition animation and gesture interaction in Interface Builder. As of this writing, IBAnimatable is the first and the only one open source library supports those features.

Configuring Present transition in Interface Builder

There are two ways to configure Present transition in Interface Builder with IBAnimatable. The first one is to use AnimatableViewController

Firstly, select a UIViewController then configure the custom class to AnimatableViewController in Identity inspector ()

Then we can configure Transition Animation, Transition Duration and Interactive Gesture properties in Attributes inspector ().

PropertyDescriptionExample
Transition AnimationThe animation effect when Present or Dismiss a ViewController, you can find all supported transition animations in Transition Animators section. Please notices, The animators named with System*** do not support the Present transition.Fade for fade animation, some animator can support parameters, e.g. Portal(Forward) for portal forward animation, and Portal(Backward) for portal backward animation.
Transition DurationThe duration of the transition animation in seconds. The default value is 0.70.5 means half a second, 2 means two seconds
Interactive GestureThe gesture used to Dismiss the ViewController, you can find all supported interactive gestures in Interactive Animators section. There is no gesture for Dismiss if it is unset (nil). Some Transition Animator has a default gesture, you can set this property to Default to use the default gesture. You can find all default gesture in Transition AnimatorsDefault for FadeAnimator is Pan(Horizontal) gesture which means pan horizontally. And Pinch(Close) means pinch close gesture.

Once we configure those properties, ALL Transition (please notice it is all, including Present and Exit Segues) for this ViewController will use the configured animation effect. The transition animation will look like this based on the settings above.

You can see the example in "TransitionsInInterfaceBuilder.storyboard" and play around different configurations. Then open the App and tap on "Playground" button, and tap on "transitions" cell to navigate to Transitions Scene. Tap on "IB" button to see the configurations you made in "TransitionsInInterfaceBuilder.storyboard".

If you want to have separate animation effect for different Present Transition, see the section Configuring Present transition in Interface Builder via Segue.

Configuring Present transition in Interface Builder via Segue

In some case, we may want to have different animation effect for various Present Transition. IBAnimatable provides a set of custom Segues to support that. You can find all supported Segues in Segues section.

To use custom Segue, we can control drag from one ViewController to another ViewController, then select a custom Segue e.g. "present portal with dismiss interaction". Because Interface Builder doesn't support @IBInspectable for Segue, we are not able to change the transition direction, duration and dismissal gesture. There are one or two Segues for each Transition Animator. One is without dismissal interaction, and one's with (if this transition animator has interactive dismissal gesture). For example, for PortalAnimator, we have "present portal" for Portal animation without dismissal interaction, and have "present portal with dismiss interaction" for Portal animation with default dismissal interaction, which is Pinch(Close).

After we select "present portal with dismiss interaction", we need to check the Module in Attributes inspector (). The App may crash if the field is empty. It probably is a bug of Interface Builder. To fix it just simply click on the Module field and hit enter, it should show IBAnimatable. If everything is ready, we can see the transition animation like this as below. We can have more than one Segue within the same ViewController. They will have different transition animation based on the selected Segue.

You can see the example in "TransitionsInInterfaceBuilder.storyboard" and play around different configurations.

Configuring Push transition in Interface Builder

To use Push transition, we need to have a UINavigationController. Firstly, select a UINavigationController then set the class to AnimatableNavigationController in Identity inspector ()

Then we can configure Transition Animation, Transition Duration and Interactive Gesture properties in Attributes inspector (). Those properties are as same as in Configuring Present transition in Interface Builder section. The differences are we can use System***Animator classes in Transition Animation, e.g. SystemCube(Left) for System Cube transtion.

Once we configure those properties, all Push Transitions inside the NavigationController will use the configured animation effect. We usually don't have different effects inside the same NavigationController, so we don't provide Push Segues to support different transition animations. If you still want to have different transition animations, we can use Apple default API to achieve that. Please check out UINavigationControllerDelegate.

You can see the example in "TransitionsInInterfaceBuilder.storyboard" and play around different configurations.

Transition Animators

IBAnimatable provide a broad set of Transition Animators / Controllers. We can use them in Interface Builder as Transition Animation as described in Configuring Present transition in Interface Builder and Configuring Push transition in Interface Builder, or programmatically in code. They are all standard Transition Animators / Controllers conform to UIViewControllerAnimatedTransitioning.

You can see all supported Transition Animators in the demo App, open the App and tap on "Playground" button, then tap on "transitions" cell to see all transitions.

FadeAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
FadeCross fadePan(Horizontal)
Fade(In)Fade inPan(Horizontal)
Fade(Out)Fade outPan(Horizontal)

SystemCubeAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemCube(Left)Cube effect from leftPan(Right)
SystemCube(Right)Cube effect from RightPan(Left)
SystemCube(Top)Cube effect from topPan(Bottom)
SystemCube(Bottom)Cube effect from bottomPan(Top)

Please notice, it doesn't support the Present transition.

SystemFlipAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemFlip(Left)Flip from leftPan(Right)
SystemFlip(Right)Flip from RightPan(Left)
SystemFlip(Top)Flip from topPan(Bottom)
SystemFlip(Bottom)Flip from bottomPan(Top)

Please notice, it doesn't support the Present transition.

SystemMoveInAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemMoveIn(Left)Move in from leftPan(Right)
SystemMoveIn(Right)Move in from RightPan(Left)
SystemMoveIn(Top)Move in from topPan(Bottom)
SystemMoveIn(Bottom)Move in from bottomPan(Top)

Please notice, it doesn't support the Present transition.

SystemPushAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemPush(Left)Push from leftPan(Right)
SystemPush(Right)Push from rightPan(Left)
SystemPush(Top)Push from topPan(Bottom)
SystemPush(Bottom)Push from bottomPan(Top)

Please notice, it doesn't support the Present transition.

SystemRevealAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemReveal(Left)Reveal from leftPan(Right)
SystemReveal(Right)Reveal from RightPan(Left)
SystemReveal(Top)Reveal from topPan(Bottom)
SystemReveal(Bottom)Reveal from bottomPan(Top)

Please notice, it doesn't support the Present transition.

SystemPageAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemPage(Curl)Page curl effectNone
SystemPage(UnCurl)Page uncurl effectNone

Please notice, it doesn't support Present transtion.

SystemCameralrisAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemCameralrisCameralris close and open effectPinch(Close)
SystemCameralris(HollowOpen)Cameralris open effectPinch(Close)
SystemCameralris(HollowClose)Cameralris close effectPinch(Open)

Please notice, it doesn't support the Present transition.

FoldAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
Fold(Left)Fold from leftPan(Right)
Fold(Right)Fold from RightPan(Left)
Fold(Top)Fold from topPan(Bottom)
Fold(Bottom)Fold from bottomPan(Top)

FoldAnimator also supports second parameter folds, which sets the number of folds. The default value is 2. We can use it like Fold(Left,5).

PortalAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
Portal(Forward)Portal forward effectPinch(Close)
Portal(Backward)Portal backward effectPinch(Open)

PortalAnimator also supports second parameter zoomScale, which sets the origin scale of the scene, the value range is from 0 to 1, the default value is 0.8. We can use it like Portal(Forward,0.5).

NatGeoAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
NatGeo(Left)NatGeo effect to leftNone
NatGeo(Right)NatGeo effect to RightNone

TurnAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
Turn(Left)Turn from leftPan(Right)
Turn(Right)Turn from RightPan(Left)
Turn(Top)Turn from topPan(Bottom)
Turn(Bottom)Turn from bottomPan(Top)

CardsAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
Cards(Forward)Cards effect forwardNone
Cards(Backward)Cards effect backwardNone

FlipAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
Flip(Left)Flip from leftPan(Right)
Flip(Right)Flip from RightPan(Left)

SlideAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
Slide(Left)Slide to leftPan(Left)
Slide(Right)Slide to RightPan(Right)
Slide(Top)Slide to topPan(Top)
Slide(Bottom)Slide to bottomPan(Bottom)

SlideAnimator also supports second parameter fade, which set the scene to fade in. If we don't specify the second parameter, it doesn't have a fade effect. We can use it like Slide(left,fade).

SystemRotateAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemRotateRotate 90 degreesNone

Please notice, it doesn't support the Present transition.

SystemRippleEffectAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemRippleEffectRipple effectNone

Please notice, it doesn't support the Present transition.

SystemSuckEffectAnimator

Using in Transition Animation

ValueEffectDefault Interactive Animator
SystemSuckEffectSuck effectNone

Please notice, it doesn't support the Present transition.

Explode

Using in Transition Animation

ValueEffectDefault Interactive Animator
ExplodeExplode effectNone

ExplodeAnimator also supports parameters 0. xFactor: How many pieces in one row when explodes. The default value is 10 0. minAngle: The minimum angle for the pieces when the explode animation runs. The default value is -10 0. maxAngle: The maximum angle for the pieces when the explode animation runs. The default value is 10

We can use them like `Explode(20,-5,5)

Interactive Animators

We can use Interactive Animators / Controllers to configure gesture for Dismiss or Pop transition in Interface Builder or use them programmatically, please refer to UINavigationControllerDelegate and UIViewControllerTransitioningDelegate.

PanInteractiveAnimator

ValueGesture
Pan(Horizontal)Pan horizontally
Pan(Vertical)Pan vertically
Pan(Left)Pan from left
Pan(Right)Pan from right
Pan(Top)Pan from top
Pan(Bottom)Pan from bottom

ScreenEdgePanInteractiveAnimator

ValueGesture
ScreenEdgePan(Horizontal)ScreenEdgePan horizontally
ScreenEdgePan(Vertical)ScreenEdgePan vertically
ScreenEdgePan(Left)ScreenEdgePan from left
ScreenEdgePan(Right)ScreenEdgePan from right
ScreenEdgePan(Top)ScreenEdgePan from top
ScreenEdgePan(Bottom)ScreenEdgePan from bottom

Please notice, ScreenEdgePan(Vertical), ScreenEdgePan(Top) and ScreenEdgePan(Bottom) are reserved by iOS system. In most of cases, we should not use them.

PinchInteractiveAnimator

ValueGesture
PinchPinch open or close
Pinch(Close)Pinch close
Pinch(Open)Pinch open

You can play around the configurations in "TransitionsInInterfaceBuilder.storyboard".

Segues

To support different animation effect for different Prsent transition, IBAnimatable provides a set of Present Segues.

Present Segues

ValueDescription
PresentFadeSeguePresent segue with fade transition
PresentFadeWithDismissInteractionSeguePresent segue with fade transition, using Pan(Horizontal) gesture to dismiss
PresentFoldSeguePresent segue with fold from left transition
PresentFoldWithDismissInteractionSeguePresent segue with fold from left transition, using Pan(Right) gesture to dismiss
PresentPortalSeguePresent segue with portal forward transition
PresentPortalWithDismissInteractionSeguePresent segue with portal forward transition, using Pinch(Close) gesture to dismiss
PresentTurnSeguePresent segue with turn from left transition
PresentTurnWithDismissInteractionSeguePresent segue with turn from left transition, using Pan(Right) gesture to dismiss
PresentFlipSeguePresent segue with flip from left transition
PresentFlipWithDismissInteractionSeguePresent segue with flip from left transition, using Pan(Right) gesture to dismiss
PresentSlideSeguePresent segue with slide to left transition
PresentSlideWithDismissInteractionSeguePresent segue with slide to left transition, using Pan(Left) gesture to dismiss
PresentCardsSeguePresent segue with cards effect transition
PresentNatGeoSeguePresent segue with NatGeo effect transition
PresentExplodeSeguePresent segue with explode effect transition

Exit Segues

IBAnimatale provide some Exit Segues to help the user configure Exit / Unwind actions. To do that, we can "control drag" from a button to "Exit" icon (on top of the ViewController), then select the Segue.

ValueDescription
dismissCurrentViewControllerdismiss current ViewController, it is an exit action for Present transition
popToRootViewControllerpop to root ViewController, it can directly pop to root of the NavigationController
unwindToViewControllerunwind to previous ViewController

Contribution

Great thanks to @tbaranes who ported all transitions from VCTransitionsLibrary and added parameters support for some transition animators.

If you'd like to add more transition animations to IBAnimatable, it is super easy, please have a look at How to develop an animator (animation controller). Let's have some fun 😉. You can also discuss that in Issue 155 - Custom transition animators (animation controllers). If you have any question, please contact @JakeLin.