Reputation: 4634
I am coming from this question: How to change the Push and Pop animations in a navigation based app
I wanted to reverse the animation for push and pop. So that, instead of the default animating to Right, it should go to the Left and vice versa.
I created a subclass of UINavigationController
and override the push and pop methods.
Here is the code:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:nil];
[super pushViewController:viewController animated:NO];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;//kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromRight; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:transition forKey:nil];
UIViewController *poppedVC = [super popViewControllerAnimated:NO];
return poppedVC;
}
So far, these are working perfectly.
In these methods, the line [self.view.layer addAnimation:transition forKey:nil];
is making me confused. I see that on every call to the methods a new CATransition
object is initialized and added to the layer of the view. I am not sure whats the effect of this on memory. Is it safe and if not, what should I do so that it won't harm memory/performance?
Upvotes: 0
Views: 419
Reputation: 5157
An easy solution would be to add a CATransition ivar (or property) and reuse that every time. That said, I doubt this will affect performance noticeably and it's not usually useful to worry about performance until you've established that it is an issue.
So, in short, don't worry about it. If you ARE worried about it, make a single ivar that is used in each of these methods.
Upvotes: 1