sonics876
sonics876

Reputation: 957

Using 'pushViewController' animation when switching between tabs in UITabController

I am having trouble trying to make the UITabBarViewController perform the same animation that UINavigationController has when it performs pushViewController.

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

UIViewController *currentVC = [tabBarController selectedViewController];
if (currentVC == viewController) 
    return NO;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
UIModalTransitionStyle transition = UIModalTransitionStyleFlipHorizontal;
[UIView setAnimationTransition:transition forView:tabBarController.view cache:YES];
[currentVC viewWillAppear:YES];
[viewController viewWillDisappear:YES];
[viewController viewDidDisappear:YES];
[currentVC viewDidAppear:YES];
[UIView commitAnimations];
return YES;}

The following code performs an animation when switching tabs:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

UIViewController *currentVC = [tabBarController selectedViewController];
if (currentVC == viewController) 
    return NO;

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

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:tabBarController.view cache:YES];
[currentVC viewWillAppear:YES];
[viewController viewWillDisappear:YES];
[viewController viewDidDisappear:YES];
[currentVC viewDidAppear:YES];
[UIView commitAnimations];

return YES;}

How can I modify the code above to perform the slide from the right animation similar to pushing a a viewController into the navigation controller?

Upvotes: 2

Views: 1029

Answers (1)

Christian
Christian

Reputation: 1714

Take a look at this link: http://haveacafe.wordpress.com/2009/04/06/animated-transition-between-tabbars-view-on-iphone/

The idea is, you need to use the tab bar controller's delegate method and use the specific animation class CATransition (since you are 'transitioning' between views). Take a look at the CATransition documentation for the types / subtypes for the animation. You'll probably want a type of push with a subtype of left or right.

Upvotes: 1

Related Questions