When i push a viewcontroller the animation is always from right to left. I want to change that animation to the inverse left to right. I have tried this code but doesnt work. The animation is still from right to left. How can i achive this simply and correctly? Need help please. Thanks in advance.
//NOT WORKING
myViewController *mController = [self.storyboard instantiateViewControllerWithIdentifier:@"myViewController"];
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:mController animated:YES];
Assuming
myViewController
is your view controller,You can try this as well.
If some one is looking for the same answer in Xamarin.iOS (based on gran33 answer) :
You are actually doing it right, but as far as I understand from your code, you are not overriding the method:
So, you need to inherit from
UINavigationController
and override the above method.Here's how I do it (push + pop):
Push:
Pop :
Since this question mentions iOS 7 I'm quite surprised the answer doesn't mention the Animated Transitions API introduced in iOS 7.
If you want to get straight into GitHub the objc.io guys have a great post with a linked project here
Take a look at the documentation and you will see the following:
Or in Objective-C
What this means is that from iOS 7 you can control how the navigation controller implements its animations for pushes and pops.
All that is needed is for you to set the delegate of the navigation controller and vend the correct animator object when appropriate. So lets get started:
1. Set the UINavigationControllerDelegate
I typically like to have an App-Wide Navigation Coordinator that manages all my transitions etc. So ideally you want some object that will be alive for the duration of the NavigationController. So we might have a coordinator that looks like this:
I typically create this in the App Delegate so it can be referenced anywhere. You could also set the delegate on a per view controller basis, creating a custom UINavigationController subclass, or wherever you see fit.
2. Create A Custom Animator
Now we need an object that conforms to the
UIViewControllerAnimatedTransitioning
protocol. This object will be called upon to apply the animation whenever an animated transition is needed. This example is a simple animation that fades and expands the fromView in the transition so its relevant for a Push.3. Vend The Animator Where Necessary
Now we need to implement the UINavigationController delegate and vend our custom animator when needed.
And there you go, you now have total control over your UINavigationController transitions
Try Above code