-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOldStyleNavigationControllerAnimatedTransition.m
More file actions
58 lines (48 loc) · 1.78 KB
/
OldStyleNavigationControllerAnimatedTransition.m
File metadata and controls
58 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// SXTNavigationControllerAnimatedTransition.m
//
//
// Created by Davide Di Stefano on 16/09/13.
// Copyright (c) 2013 ReturnService. All rights reserved.
//
#import "OldStyleNavigationControllerAnimatedTransition.h"
@implementation OldStyleNavigationControllerAnimatedTransition
- (id)init {
self = [super init];
if (self) {
_operation = UINavigationControllerOperationPush;
}
return self;
}
- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext;
{
return 0.35;
}
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext;
{
UIViewController * fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController * toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
CGRect screenFrame = fromViewController.view.frame;
UIView * containerView = [transitionContext containerView];
[containerView addSubview:toViewController.view];
CGFloat toStartX, fromEndX;
if (_operation == UINavigationControllerOperationPush)
{
toStartX = screenFrame.size.width;
fromEndX = -screenFrame.size.width;
} else
{
toStartX = -screenFrame.size.width;
fromEndX = screenFrame.size.width;
}
toViewController.view.frame = CGRectOffset(screenFrame, toStartX, 0);
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^
{
toViewController.view.frame = screenFrame;
fromViewController.view.frame = CGRectOffset(screenFrame, fromEndX, 0);
} completion:^(BOOL finished) {
[fromViewController.view removeFromSuperview];
[transitionContext completeTransition:YES];
}];
}
@end