Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added reverse animation #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Transition Delegate/AnimatedTransitioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
// 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 <Foundation/Foundation.h>

@interface AnimatedTransitioning : NSObject <UIViewControllerAnimatedTransitioning>

@property (nonatomic, assign) BOOL isPresenting;
@property (nonatomic, assign) BOOL reverse;

@end
38 changes: 30 additions & 8 deletions Transition Delegate/AnimatedTransitioning.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -20,26 +19,49 @@ - (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)
return 0.25f;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)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<UIViewControllerContextTransitioning>)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) {
[transitionContext completeTransition:YES];
}];
}

-(void)executeReverseAnimation:(id<UIViewControllerContextTransitioning>)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
13 changes: 6 additions & 7 deletions Transition Delegate/TransitionDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//

Expand All @@ -17,17 +18,15 @@ @implementation TransitionDelegate
//===================================================================

- (id <UIViewControllerAnimatedTransitioning>)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 <UIViewControllerAnimatedTransitioning>)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 <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator {
Expand Down