diff --git a/Transition Delegate/AnimatedTransitioning.h b/Transition Delegate/AnimatedTransitioning.h index 2f4d0cb..36184f4 100644 --- a/Transition Delegate/AnimatedTransitioning.h +++ b/Transition Delegate/AnimatedTransitioning.h @@ -3,6 +3,7 @@ // CustomTransitionExample // // Created by Blanche Faur on 10/24/13. +// Updated by Anthony Detamore on 9/03/14. // Copyright (c) 2013 Blanche Faur. All rights reserved. // @@ -10,6 +11,6 @@ @interface AnimatedTransitioning : NSObject -@property (nonatomic, assign) BOOL isPresenting; +@property (nonatomic, assign) BOOL reverse; @end diff --git a/Transition Delegate/AnimatedTransitioning.m b/Transition Delegate/AnimatedTransitioning.m index c346517..67b41c2 100644 --- a/Transition Delegate/AnimatedTransitioning.m +++ b/Transition Delegate/AnimatedTransitioning.m @@ -3,12 +3,11 @@ // CustomTransitionExample // // Created by Blanche Faur on 10/24/13. +// Updated by Anthony Detamore on 9/03/14 // Copyright (c) 2013 Blanche Faur. All rights reserved. // #import "AnimatedTransitioning.h" -#import "MainViewController.h" -#import "SecondViewController.h" @implementation AnimatedTransitioning @@ -20,20 +19,28 @@ - (NSTimeInterval)transitionDuration:(id ) return 0.25f; } -- (void)animateTransition:(id )transitionContext { +- (void)animateTransition:(id )transitionContext +{ + UIViewController* toVC = (UIViewController*)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; + UIViewController* fromVC = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; - UIView *inView = [transitionContext containerView]; - SecondViewController *toVC = (SecondViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; - MainViewController *fromVC = (MainViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; + if(self.reverse) { + [self executeReverseAnimation:transitionContext fromVC:fromVC toVC:toVC]; + } else { + [self executeForwardAnimation:transitionContext fromVC:fromVC toVC:toVC]; + } - [inView addSubview:toVC.view]; +} + +-(void)executeForwardAnimation:(id)transitionContext fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC +{ + [[transitionContext containerView] addSubview:toVC.view]; CGRect screenRect = [[UIScreen mainScreen] bounds]; [toVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; [UIView animateWithDuration:0.25f animations:^{ - [toVC.view setFrame:CGRectMake(0, 0, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; } completion:^(BOOL finished) { @@ -41,5 +48,20 @@ - (void)animateTransition:(id )transitionC }]; } +-(void)executeReverseAnimation:(id)transitionContext fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC +{ + [[transitionContext containerView] insertSubview:toVC.view belowSubview:fromVC.view]; + + CGRect screenRect = [[UIScreen mainScreen] bounds]; + + [UIView animateWithDuration:0.25f + animations:^{ + [fromVC.view setFrame:CGRectMake(0, screenRect.size.height, fromVC.view.frame.size.width, fromVC.view.frame.size.height)]; + } + completion:^(BOOL finished) { + [transitionContext completeTransition:YES]; + }]; +} + @end diff --git a/Transition Delegate/TransitionDelegate.m b/Transition Delegate/TransitionDelegate.m index 23c31b9..b91bcf2 100644 --- a/Transition Delegate/TransitionDelegate.m +++ b/Transition Delegate/TransitionDelegate.m @@ -3,6 +3,7 @@ // CustomTransitionExample // // Created by Blanche Faur on 10/24/13. +// Updated by Anthony Detamore on 9/03/14. // Copyright (c) 2013 Blanche Faur. All rights reserved. // @@ -17,17 +18,15 @@ @implementation TransitionDelegate //=================================================================== - (id )animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source { - AnimatedTransitioning *controller = [[AnimatedTransitioning alloc]init]; - controller.isPresenting = YES; + AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; + [controller setReverse:NO]; return controller; } - (id )animationControllerForDismissedController:(UIViewController *)dismissed { -//I will fix it later. -// AnimatedTransitioning *controller = [[AnimatedTransitioning alloc]init]; -// controller.isPresenting = NO; -// return controller; - return nil; + AnimatedTransitioning *controller = [[AnimatedTransitioning alloc] init]; + [controller setReverse:YES]; + return controller; } - (id )interactionControllerForPresentation:(id )animator {