使用“pushViewController”在 UITabController 中的选项卡之间切换时的动画

发布于 2024-11-02 00:50:21 字数 1586 浏览 11 评论 0原文

我在尝试使 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 推入导航控制器?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的痛♀有谁懂 2024-11-09 00:50:21

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

这个想法是,你需要使用选项卡bar 控制器的委托方法并使用特定的动画类 CATransition (因为您在视图之间“转换”)。查看 CATransition 文档,了解动画的类型/子类型。您可能需要一种带有 left 或 right 子类型的推送类型。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文