2 "name": "TransitionManager",
4 "summary": "Painless custom transitioning. Easy extend, easy setup, just focus on animations.",
5 "description": "TransitionManager\n=================\n\nPainless custom transitioning. Easy extend, easy setup, just focus on animations.\n\n\nUsage\n-----\n\nCopy & paste `TransitionManager.swift` into your project.\n\n- Declare a `TransitionManager` object.\n- Init it with a [`TransitionManagerAnimation`](#Create)\n- Assign it as your navigation controller's delegate if you use navigation controller.\n - Else assign it as your view controller's `transitioningDelegate`.\n\n``` swift\n\n\tvar transition: TransitionManager!\n\n\toverride func viewDidLoad() {\n\t super.viewDidLoad()\n\n\t transition = TransitionManager (transitionAnimation: FadeTransitionAnimation())\n\t navigationController?.delegate = transition\n\t}\n\n```\n\n\nCreating Transition Animations <a id=\"Create\"></a>\n-----\n\n\nCreate a subclass of `TransitionManagerAnimation`\n\n``` swift\n\tclass FadeTransitionAnimation: TransitionManagerAnimation {\n\n\t}\n```\n\n`TransitionManagerAnimation` class implements `TransitionManagerDelegate` protocol.\n\n##### TransitionManagerDelegate <a id=\"Delegate\"></a>\n\n``` swift\n\n\tprotocol TransitionManagerDelegate {\n\n\t func transition (\n\t container: UIView,\n\t fromViewController: UIViewController,\n\t toViewController: UIViewController,\n\t duration: NSTimeInterval,\n\t completion: ()->Void)\n\n\t var interactionTransitionController: UIPercentDrivenInteractiveTransition? { get set }\n\t}\n\n```\n\nFor transition animation, we should override `transition` func and write our custom animation in it.\n\n``` swift\n\nclass FadeTransitionAnimation: TransitionManagerAnimation {\n\n override func transition (\n container: UIView,\n fromViewController: UIViewController,\n toViewController: UIViewController,\n duration: NSTimeInterval,\n completion: ()->Void) {\n\n let fromView = fromViewController.view\n let toView = toViewController.view\n\n container.addSubview(toView)\n toView.alpha = 0\n\n UIView.animateWithDuration(\n duration,\n animations: {\n toView.alpha = 1\n },\n completion: { finished in\n completion ()\n })\n }\n}\n\n```\n\nOne important part is `completion()` must be called because the `TransitionManager` finishes transition after it gets called.\n\n\n### Interaction Transition\n\nCreate a `TransitionManagerAnimation` subclass and write an initilizer with `UINavigationController` parameter.\n\nAdd its `view` a pan gesture\n\n``` swift\n\tclass LeftTransitionAnimation: TransitionManagerAnimation {\n\n\t var navigationController: UINavigationController!\n\n\t init (navigationController: UINavigationController) {\n\t super.init()\n\n\t self.navigationController = navigationController\n\t self.navigationController.view.addGestureRecognizer(UIPanGestureRecognizer (target: self, action: Selector(\"didPan:\")))\n\t }\n\n\t}\n```\n\nWe will update `interactionTransitionController` variable in [`TransitionManagerDelegate`](#Delegate) in gesture handler.\n\n``` swift\n func didPan (gesture: UIPanGestureRecognizer) {\n let percent = gesture.translationInView(gesture.view!).x / gesture.view!.bounds.size.width\n\n switch gesture.state {\n case .Began:\n interactionTransitionController = UIPercentDrivenInteractiveTransition()\n navigationController.popViewControllerAnimated(true)\n\n case .Changed:\n interactionTransitionController!.updateInteractiveTransition(percent)\n\n case .Ended:\n if percent > 0.5 {\n interactionTransitionController!.finishInteractiveTransition()\n } else {\n interactionTransitionController!.cancelInteractiveTransition()\n }\n interactionTransitionController = nil\n\n default:\n return\n }\n }\n```\n\nInteraction transition has 3 parts:\n* Init `interactionTransitionController` and either pop or push navigation controller when gesture (interaction) starts.\n* Calculate your `percent`s on gesture change and `updateInteractiveTransition:` with that percent\n* When gesture ended, decide if your transition complete or not and give information to your `interactionTransitionController` with `finishInteractiveTransition ()` and `cancelInteractiveTransition ()`\n\n\n### Easier `TransitionManager` setup\n\nYou can create a `TransitionManagerAnimation` container enum and give it all your animations\n\n``` swift\n\tenum TransitionManagerAnimations {\n\t case Fade\n\t case Left\n\t}\n```\n\nWrite a func that returns correct transition animation in enum\n\n``` swift\n\tenum TransitionManagerAnimations {\n\t case Fade\n\t case Left (UINavigationController)\n\n\t func transitionAnimation () -> TransitionManagerAnimation {\n\t switch self {\n\t case .Fade:\n\t return FadeTransitionAnimation()\n\n\t case .Left (let nav):\n\t return LeftTransitionAnimation(navigationController: nav)\n\n\t default:\n\t return TransitionManagerAnimation()\n\t }\n\t }\n\t}\n```\n\nExtend `TransitionManager` and write a new init method like\n\n``` swift\n\n\textension TransitionManager {\n\n\t convenience init (transition: TransitionManagerAnimations) {\n\t self.init (transitionAnimation: transition.transitionAnimation())\n\t }\n\t}\n\n```\n\nNow you can create `TransitionManager` in your view controller like\n\n``` swift\n\ttransition = TransitionManager (transition: .Left(navigationController!))\n\tnavigationController?.delegate = transition\n```",
6 "homepage": "https://github.com/cemolcay/TransitionManager",
9 "cemolcay": "ccemolcay@gmail.com"
15 "git": "https://github.com/cemolcay/TransitionManager.git",
18 "source_files": "TransitionManager/TransitionManager/*.swift",