在UITabbarController中切换选项卡时使用'pushViewController'动画

时间:2011-04-19 14:49:26

标签: iphone interface mobile uitabcontroller

我在尝试使UITabBarViewController执行与UINavigationController执行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;}

以下代码在切换标签时执行动画:

- (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;}

如何修改上面的代码以从右侧动画执行幻灯片,类似于将viewController推送到导航控制器?

2 个答案:

答案 0 :(得分:1)

请看一下这个链接:http://haveacafe.wordpress.com/2009/04/06/animated-transition-between-tabbars-view-on-iphone/

这个想法是,您需要使用标签栏控制器的委托方法并使用特定的动画类CATransition(因为您在视图之间'转换')。看一下CATransition documentation的动画类型/子类型。你可能想要一种左或右子类型的推送。

答案 1 :(得分:0)

请查看此链接:http://www.iphoneexamples.com/以了解基本的动画内容。