iPhone - 动画TabBarController开关 [英] iPhone - Animate TabBarController Switches

查看:134
本文介绍了iPhone - 动画TabBarController开关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过切换code卡口与这样的:

I am switching tabs through code with this:

self.tabBarController.selectedIndex = 1; // or any other number

标签之间的切换工作正常。我不知道是否有动画的过渡方式。它不得不只在这种情况下,不是一般的总tabbarcontroller。这就是说,当标签通过特定件code的切换过渡才会发生。它应该是瞬间(无动画)的实际标签项被点击时。

The switching between the tabs works fine. I'm wondering if there is a way to animate the transition. It'd have to be only in this instance, not the total tabbarcontroller in general. That is to say that the transition will only take place when the tab is switched through that specific piece of code. It should be instantaneous(without animation) when the actual tab item is clicked.

如果任何人都可以帮助,帮助是多少AP preciated。

If anyone can help, help is much appreciated.

推荐答案

如果你没有什么复杂的标签栏控制器回事,你可以从一个的UITabBar滚你自己,然后你可以做你想做什么时你切换标签。你只要贯彻 UITabBarDelegate 。这里是例如code,从我使用的应用程序是什么稍作修改:

If you don't have anything complicated going on with the tab bar controller, you can roll your own from a UITabBar and then you can do anything you want when you switch tabs. You just implement the UITabBarDelegate. Here is example code slightly modified from what I'm using in an app:

.h文件中:

@interface AllGames : UIViewController <UITabBarDelegate> {
    IBOutlet UITabBar *tabBar;
}
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;

.m文件:

@implementation AllGames

@synthesize tabBar;

UIViewController *subviews[3];

- (void)viewDidLoad {
    [super viewDidLoad];

    int startTab = [Preferences LookupPreferenceInt:CFSTR("GameTab")];
    [tabBar setSelectedItem:[tabBar.items objectAtIndex:startTab]];

    Games1 *vc1 = [[Games1 alloc] initWithNibName:@"Games1" bundle:nil];
    Games2 *vc2 = [[Games2 alloc] initWithNibName:@"Games2" bundle:nil];
    Games3 *vc3 = [[Games3 alloc] initWithNibName:@"Games3" bundle:nil];

    subviews[0] = vc1;
    subviews[1] = vc2;
    subviews[2] = vc3;
    vc1.view.alpha = 0;
    vc2.view.alpha = 0;
    vc3.view.alpha = 0;
    [self.view addSubview:vc1.view];
    [self.view addSubview:vc2.view];
    [self.view addSubview:vc3.view];
    subviews[startTab].view.alpha = 1.0;
}

- (void)dealloc {
    [Preferences StorePreferenceInt:CFSTR("GameTab") withValue:[tabBar selectedItem].tag-1];
    for (int x = 0; x < 3; x++)
    {
        [subviews[x].view removeFromSuperview];
        [subviews[x] release];
        subviews[x] = 0;
    }
    [super dealloc];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    printf("Hit item tag: %d\n", item.tag);
    for (int x = 1; x <= 3; x++)
    {
        subviews[x-1].view.alpha = (x == item.tag)?1.0:0.0;
    }
}

里面didSelectItem你可以做任何你想要的动画。我只是做了阿尔法的直接交换,但你可以像你想的那么复杂。

Inside didSelectItem you can do any animation you want. I just do an immediate swap of the alpha, but you can be as complicated as you want.

这篇关于iPhone - 动画TabBarController开关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆