Swift
Need help with TransitionManager?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
cemolcay

Description

Painless custom transitioning. Easy extend, easy setup, just focus on animations.

201 Stars 22 Forks MIT License 37 Commits 1 Opened issues

Services available

Need anything else?

TransitionManager

Painless custom transitioning. Easy extend, easy setup, just focus on animations.

Installation

CocoaPods

You can use CocoaPods to install

TransitionManager
by adding it to your
Podfile
:
platform :ios, '8.0'
use_frameworks!
pod 'TransitionManager'

To get the full benefits import

TransitionManager
wherever you import UIKit
import UIKit
import TransitionManager

Manually

  1. Download and drop
    /TransitionManager
    folder in your project.
  2. Congratulations!

Usage

Copy & paste

TransitionManager.swift
into your project.
  • Declare a
    TransitionManager
    object.
  • Init it with a
    TransitionManagerAnimation

  • Assign it as your navigation controller's delegate if you use navigation controller.
    • Else assign it as your view controller's
      transitioningDelegate
      .
    var transition: TransitionManager!

override func viewDidLoad() {
   super.viewDidLoad()

   transition = TransitionManager (transitionAnimation: FadeTransitionAnimation())
   navigationController?.delegate = transition
}

Creating Transition Animations

Create a subclass of

TransitionManagerAnimation
    class FadeTransitionAnimation: TransitionManagerAnimation {

}

TransitionManagerAnimation
class implements
TransitionManagerDelegate
protocol.
TransitionManagerDelegate
protocol TransitionManagerDelegate {

/// Transition nimation method implementation
func transition(
    container: UIView,
    fromViewController: UIViewController,
    toViewController: UIViewController,
    isDismissing: Bool,
    duration: NSTimeInterval,
    completion: () -> Void)

/// Interactive transitions,
/// update percent in gesture handler
var interactionTransitionController: UIPercentDrivenInteractiveTransition? { get set }

}

For transition animation, we should override

transition
func and write our custom animation in it.
class FadeTransitionAnimation: TransitionManagerAnimation {
    override func transition(
        container: UIView,
        fromViewController: UIViewController,
        toViewController: UIViewController,
        isDismissing: Bool,
        duration: NSTimeInterval,
        completion: () -> Void) {
        if isDismissing {
            closeAnimation(container,
                fromViewController: fromViewController,
                toViewController: toViewController,
                duration: duration,
                completion: completion)
        } else {
            openAnimation(container,
                fromViewController: fromViewController,
                toViewController: toViewController,
                duration: duration,
                completion: completion)
        }
    }    
}

One important part is

completion()
must be called because the
TransitionManager
finishes transition after it gets called.

Interaction Transition

Interaction transition has 3 parts: * Init

interactionTransitionController
and either pop or push navigation controller when gesture (interaction) starts. * Calculate your
percent
s on gesture change and
updateInteractiveTransition:
with that percent * When gesture ended, decide if your transition complete or not and give information to your
interactionTransitionController
with
finishInteractiveTransition ()
and
cancelInteractiveTransition ()

Easier
TransitionManager
setup

You can create a

TransitionManagerAnimation
container enum and give it all your animations
    enum TransitionManagerAnimations {
        case Fade
        case Pull
    }

Write a func that returns correct transition animation in enum

enum TransitionManagerAnimations {
    case Fade
    case Pull

func transitionAnimation () -> TransitionManagerAnimation {
    switch self {
    case .Fade:
        return FadeTransitionAnimation()
    case .Pull:
        return PullTransitionAnimation()
    }
}

}

Extend

TransitionManager
and write a new init method like
extension TransitionManager {
    convenience init(transition: TransitionManagerAnimations) {
        self.init(transitionAnimation: transition.transitionAnimation())
    }
}

Now you can create

TransitionManager
in your view controller like
transition = TransitionManager(transition: .Pull)
navigationController?.delegate = transition

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.