Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // TransitionManager.swift
- // Ritvik Choudhary
- //
- // Created by Ritvik Choudhary on 20/04/15.
- // Copyright (c) 2015 ritvik1512. All rights reserved.
- //
- import UIKit
- class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate
- {
- // MARK: UIViewControllerAnimatedTransitioning protocol methods
- // animate a change from one viewcontroller to another
- func animateTransition(transitionContext: UIViewControllerContextTransitioning)
- {
- // TODO: Perform the animation
- // get reference to our fromView, toView and the container view that we should perform the transition in
- let container = transitionContext.containerView()
- let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
- let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
- // set up from 2D transforms that we'll use in the animation
- let offScreenRight = CGAffineTransformMakeTranslation(container.frame.width, 0)
- let offScreenLeft = CGAffineTransformMakeTranslation(-container.frame.width, 0)
- // start the toView to the right of the screen
- toView.transform = offScreenRight
- // add the both views to our view controller
- container.addSubview(toView)
- container.addSubview(fromView)
- // get the duration of the animation
- let duration = self.transitionDuration(transitionContext)
- // perform the animation!
- UIView.animateWithDuration(duration, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.8, options: nil, animations: {
- fromView.transform = offScreenLeft
- toView.transform = CGAffineTransformIdentity
- }, completion: { finished in
- // tell our transitionContext object that we've finished animating
- transitionContext.completeTransition(true)
- })
- }
- }
- // return how many seconds the transiton animation will take
- func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval
- {
- return 0.5
- }
- // MARK: UIViewControllerTransitioningDelegate protocol methods
- // return the animataor when presenting a viewcontroller
- func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning?
- {
- return nil
- }
- // return the animator used when dismissing from a viewcontroller
- func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?
- {
- return nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement