viewcontroller的动画加载

时间:2012-06-11 08:18:57

标签: ios ios5

我是ios的新手,所以我可以判断我的问题。

我有一个代码可供使用。在代码中,我有一个从FSVerticalTabBarController继承的垂直tabbar控制器。我们使用此tabbar控制器在viewcontrollers之间切换。

我想要的是让viewcontrollers提出一个动画。任何类型的默认动画都可以。我怎样才能做到这一点?这是代码,谢谢你的帮助:

    @implementation AIVerticalTabBarController

@synthesize appDelegate;

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self setDelegate:self];

    [[self tabBar] setBackgroundColor:[UIColor darkGrayColor]];

    NSArray *titles = [NSArray arrayWithObjects:@"Home", @"Export", @"Settings", @"Titles", @"Slides", @"Text doc", nil];
    NSArray *viewClasses = [NSArray arrayWithObjects:@"AIViewController", @"AIViewController", @"AIViewController", @"AITitlesViewController", @"AISlidesViewController", @"AIViewController", nil];

    NSMutableArray *controllersToAdd = [[NSMutableArray alloc] init];
    for (NSUInteger i = 0; i < [titles count]; i++) {
        AIViewController *viewC = [[NSClassFromString([viewClasses objectAtIndex:i]) alloc] init];
        [viewC setAppDelegate:appDelegate];
        UITabBarItem *tbi = [[UITabBarItem alloc] initWithTitle:[titles objectAtIndex:i] image:nil tag:i];



        [viewC setTabBarItem:tbi];



        [controllersToAdd addObject:viewC];
    }

    [self setViewControllers:[NSArray arrayWithArray:controllersToAdd] animated:YES];




}
@end

1 个答案:

答案 0 :(得分:0)

您可以通过将此方法添加到appDelegate来实现 别忘了导入QuartzCore lib

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

CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionPush; //choose your animation
[viewController.view.layer addAnimation:transition forKey:nil];
[self.tabBarController.view addSubview:viewController.view];

return YES;   

CATransition *transition = [CATransition animation]; transition.duration = 1.0; transition.type = kCATransitionPush; //choose your animation [viewController.view.layer addAnimation:transition forKey:nil]; [self.tabBarController.view addSubview:viewController.view]; return YES;