Shahriyar Ahmed
Shahriyar Ahmed

Reputation: 94

Custom animation while transitioning between view controllers

I want to create transition between view controllers like this. https://www.dropbox.com/s/qatwqaq2mowocsg/Transitions%20Controller.gif?dl=0

I 've used the following code to create transition but cannot achieve following results.

self.settings = [self.storyboard instantiateViewControllerWithIdentifier:@"settings"];
CATransition* transition = [CATransition animation];

transition.duration = 0.4;
transition.type = kCATransitionPush;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.subtype=kCATransitionFromRight;


[[self navigationController].view.layer addAnimation:transition forKey:kCATransition];
[[self navigationController] pushViewController:self.settings animated:NO];

Upvotes: 2

Views: 485

Answers (3)

Chris Slowik
Chris Slowik

Reputation: 2879

While it's not a direct implementable chunk of code that represents THE ANSWER, this blog should get you through the steps to create your own custom transitions: http://blog.dadabeatnik.com/2013/10/13/custom-segues/

Upvotes: 0

user5346383
user5346383

Reputation:

You can try this code :

self.settings = [self.storyboard instantiateViewControllerWithIdentifier:@"settings"];

[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationTransition:
 UIViewAnimationTransitionFlipFromRight
                       forView:self.navigationController.view cache:NO];


[self.navigationController pushViewController:self.settings animated:YES];
[UIView commitAnimations];

Upvotes: 1

dopcn
dopcn

Reputation: 4218

Start from iOS7 you can custom the transition effect of system method pushViewController and presentViewController. For example if you need to custom the push effect there is a method in UINavigationControllerDelegate named

- (id<UIViewControllerAnimatedTransitioning> _Nullable)navigationController:(UINavigationController * _Nonnull)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController * _Nonnull)fromVC toViewController:(UIViewController * _Nonnull)toVC

add the custom animation to fromVC's view and show the toVC's view in proper time

Upvotes: 0

Related Questions