PushViewController with Custom Animation



@implementation UINavigationController (Additions)
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
/*[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];*/

CATransition* theTransition = [CATransition animation];
theTransition.duration = 0.6;
theTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
theTransition.type = kCATransitionMoveIn; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
theTransition.subtype = kCATransitionFromTop; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:theTransition forKey:nil];
[self pushViewController:controller animated:NO];
}

- (UIViewController *) popControllerWithTransition: (UIViewAnimationTransition) transition
{
/*
[UIView beginAnimations:nil context:NULL];
UIViewController *vc = [self popViewControllerAnimated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
*/

CATransition* theTransition = [CATransition animation];
theTransition.duration = 0.6;
theTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
theTransition.type = kCATransitionReveal; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
theTransition.subtype = kCATransitionFromBottom; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[self.view.layer addAnimation:theTransition forKey:nil];
UIViewController *vc = [self popViewControllerAnimated:NO];
return vc;
}
@end

About these ads

About Mustafa Shaik

Yet another developer for mobile over Symbian, Windows Mobile & iPhone/iPad.

Posted on July 1, 2011, in iOS. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: