Created
January 19, 2015 11:46
-
-
Save lhap/c960ea7c73df7a8b71f3 to your computer and use it in GitHub Desktop.
Transição Simple Segue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("nomedaview") as NOMEDAViewController | |
//animador de transição | |
viewController.transitioningDelegate = self.transitionManager | |
//passando variaveis para a proxima view | |
viewController.urlImage = url | |
viewController.name = named | |
viewController.email = email | |
self.presentViewController(viewController, animated: true, completion: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TransitionManager.swift | |
// Start | |
// | |
// Created by Plan B on 12/1/14. | |
// Copyright (c) 2014 Plan B. All rights reserved. | |
// | |
import UIKit | |
class TransitionManager: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate { | |
private var presenting = true | |
// MARK: UIViewControllerAnimatedTransitioning protocol methods | |
// animate a change from one viewcontroller to another | |
func animateTransition(transitionContext: UIViewControllerContextTransitioning) { | |
// 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 | |
// DON'T just type '0.5s' -- the reason why won't make sense until the next post | |
// but for now it's important to just follow this approach | |
let duration = self.transitionDuration(transitionContext) | |
// perform the animation! | |
// for this example, just slid both fromView and toView to the left at the same time | |
// meaning fromView is pushed off the screen and toView slides into view | |
// we also use the block animation usingSpringWithDamping for a little bounce | |
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.75 | |
} | |
// MARK: UIViewControllerTransitioningDelegate protocol methods | |
// return the animataor when presenting a viewcontroller | |
// remmeber that an animator (or animation controller) is any object that aheres to the UIViewControllerAnimatedTransitioning protocol | |
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
// these methods are the perfect place to set our `presenting` flag to either true or false - voila! | |
self.presenting = true | |
return self | |
} | |
// return the animator used when dismissing from a viewcontroller | |
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
self.presenting = false | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment