Skip to content

Commit

Permalink
Modified to use keyframe animation
Browse files Browse the repository at this point in the history
Also the completion block now passed the cancellation from the transition context.
  • Loading branch information
ColinEberhardt committed Oct 23, 2013
1 parent f75010d commit c768cd0
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions AnimationControllers/CENatGeoAnimationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC


//Perform animation
[UIView animateWithDuration:kAnimationFirstPartRatio * self.duration
delay:(1.0f - kAnimationFirstPartRatio) * self.duration
options:UIViewAnimationOptionCurveLinear animations:^{
destinationFirstTransform(toLayer);
} completion:nil];

[UIView animateWithDuration:self.duration
delay:0.0f
options:0
animations:^{
sourceFirstTransform(fromLayer);
} completion:^(BOOL finished) {
CGRect oldFrame = [fromLayer frame];
[fromLayer setAnchorPoint:CGPointMake(0.5f, 0.5f)];
[fromLayer setFrame:oldFrame];

[transitionContext completeTransition:YES];
}];
[UIView animateKeyframesWithDuration:self.duration
delay:0.0
options:UIViewKeyframeAnimationOptionCalculationModeCubic
animations:^{

[UIView addKeyframeWithRelativeStartTime:0.0f
relativeDuration:kAnimationFirstPartRatio
animations:^{
sourceFirstTransform(fromLayer);
}];

[UIView addKeyframeWithRelativeStartTime:0.0f
relativeDuration:1.0f
animations:^{
destinationFirstTransform(toLayer);
}];

} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];

} else {
fromViewController.view.userInteractionEnabled = NO;
Expand All @@ -70,22 +72,26 @@ - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionC
destinationFirstTransform(toLayer);

//Perform animation
[UIView animateWithDuration:self.duration
delay:0.0f
options:0
animations:^{
destinationLastTransform(toLayer);
} completion:nil];

[UIView animateWithDuration:kAnimationFirstPartRatio * self.duration
delay:(1.0f - kAnimationFirstPartRatio) * self.duration
options:0
animations:^{
sourceLastTransform(fromLayer);
}
completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
[UIView animateKeyframesWithDuration:self.duration
delay:0.0
options:UIViewKeyframeAnimationOptionCalculationModeCubic
animations:^{

[UIView addKeyframeWithRelativeStartTime:0.0f
relativeDuration:1.0f
animations:^{
destinationLastTransform(toLayer);
}];

[UIView addKeyframeWithRelativeStartTime:(1.0f - kAnimationFirstPartRatio)
relativeDuration:kAnimationFirstPartRatio
animations:^{
sourceLastTransform(fromLayer);
}];

} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}

}
Expand Down

0 comments on commit c768cd0

Please sign in to comment.