GithubHelp home page GithubHelp logo

nsleche / transitionmanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cemolcay/transitionmanager

0.0 2.0 0.0 90 KB

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

License: MIT License

Ruby 34.96% Swift 65.04%

transitionmanager's Introduction

TransitionManager

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

Install

CocoaPods

use_frameworks!
pod 'TransitionManager'

Manual

Copy & paste TransitionManager folder into your project.

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 percents 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

transitionmanager's People

Contributors

cemolcay avatar jeffreyjackson avatar philipheinser avatar readmecritic avatar

Watchers

James Cloos avatar Antonio Alves avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.