Last active
October 29, 2015 07:25
-
-
Save speaktoalvin/2896ea8abf12a5b7abd8 to your computer and use it in GitHub Desktop.
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
// | |
// HelloTransition.swift | |
// The Top Fives | |
// | |
// Created by Alvin Varghese on 9/13/15. | |
// Copyright (c) 2015 I dream Code. All rights reserved. | |
// | |
import UIKit | |
import Foundation | |
let kToManageReourceVC = "TO_SFSAFARI" | |
let kToSettingsVC = "TO_HOME" | |
@objc class HelloTransition : NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate { | |
var delegate : HelloTransition! | |
var transitionTo : String = "" | |
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { | |
return 0.99 | |
} | |
func animateTransition(transitionContext: UIViewControllerContextTransitioning) { | |
let sourceVC = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) | |
let destinationVC = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) | |
let container : UIView = transitionContext.containerView()! | |
let sourceRECT = transitionContext.initialFrameForViewController(sourceVC!) | |
if self.transitionTo == kToManageReourceVC { | |
destinationVC?.view.frame = CGRectMake((sourceVC?.view.frame.size.width)!, 0, sourceRECT.size.width, sourceRECT.size.height) | |
container.addSubview((destinationVC?.view)!) | |
UIView.animateWithDuration(0.30, animations: { | |
sourceVC?.view.frame = CGRectMake(-sourceRECT.size.width, 0, sourceRECT.size.width, sourceRECT.size.height) | |
destinationVC?.view.frame = CGRectMake(0, 0, sourceRECT.size.width, sourceRECT.size.height) | |
}) { _ in | |
transitionContext.completeTransition(true) | |
} | |
} | |
else { | |
destinationVC?.view.frame = CGRectMake(0, 0, sourceRECT.size.width, sourceRECT.size.height) | |
UIView.animateWithDuration(0.30, animations: { | |
sourceVC?.view.frame = CGRectMake(sourceRECT.size.width * 2, 0, sourceRECT.size.width, sourceRECT.size.height) | |
}) { _ in | |
transitionContext.completeTransition(true) | |
} | |
} | |
} | |
func animationEnded(transitionCompleted: Bool) { | |
} | |
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
return self | |
} | |
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { | |
self.transitionTo = kToSettingsVC | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment