@@ -39,6 +39,7 @@ -(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)tr
39
39
- (void )animateTransition : (id <UIViewControllerContextTransitioning>)transitionContext fromVC : (UIViewController *)fromVC toVC : (UIViewController *)toVC fromView : (UIView *)fromView toView : (UIView *)toView
40
40
{
41
41
42
+ // Calculate the direction
42
43
int dir=0 ;
43
44
switch (self.cubeAnimationType ) {
44
45
case CubeAnimationTypeNormal:
@@ -57,7 +58,8 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
57
58
CATransform3D viewToTransform;
58
59
59
60
// We create a content view for do the translate animation
60
- UIView *generalContentView = [[UIView alloc ] initWithFrame: transitionContext.containerView.bounds];
61
+ UIView *generalContentView = [transitionContext containerView ];
62
+
61
63
switch (self.cubeAnimationWay ) {
62
64
case CubeAnimationWayHorizontal:
63
65
viewFromTransform = CATransform3DMakeRotation (dir*ROTATION_ANGLE, 0.0 , 1.0 , 0.0 );
@@ -89,15 +91,11 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
89
91
// Create the shadow
90
92
UIView *fromShadow = [fromView addOpacityWithColor: [UIColor blackColor ]];
91
93
UIView *toShadow = [toView addOpacityWithColor: [UIColor blackColor ]];
92
-
93
94
[fromShadow setAlpha: 0.0 ];
94
95
[toShadow setAlpha: 1.0 ];
95
96
97
+ // Add the to- view
96
98
[generalContentView addSubview: toView];
97
- [generalContentView addSubview: fromView];
98
-
99
- // Add the toView to the container
100
- [[transitionContext containerView ] addSubview: generalContentView];
101
99
102
100
[UIView animateWithDuration: [self transitionDuration: transitionContext] animations: ^{
103
101
switch (self.cubeAnimationWay ) {
@@ -119,9 +117,10 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
119
117
[fromShadow setAlpha: 1.0 ];
120
118
[toShadow setAlpha: 0.0 ];
121
119
122
-
123
120
}completion: ^(BOOL finished) {
124
121
122
+ // Set the final position of every elements transformed
123
+ [generalContentView setTransform: CGAffineTransformIdentity];
125
124
fromView.layer .transform = CATransform3DIdentity;
126
125
toView.layer .transform = CATransform3DIdentity;
127
126
[fromView.layer setAnchorPoint: CGPointMake (0 .5f , 0 .5f )];
@@ -130,13 +129,6 @@ - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionCo
130
129
[fromShadow removeFromSuperview ];
131
130
[toShadow removeFromSuperview ];
132
131
133
- [generalContentView removeFromSuperview ];
134
-
135
- // Relocated the views
136
- [[transitionContext containerView ] addSubview: fromView];
137
- [[transitionContext containerView ] addSubview: toView];
138
- [generalContentView removeFromSuperview ];
139
-
140
132
if ([transitionContext transitionWasCancelled ]) {
141
133
[toView removeFromSuperview ];
142
134
} else {
0 commit comments