开发者

animating view change with uitabbarcontroller

I am wanting to animate my view change, however I am not sure where to put my animation since I have a UITabBarController controlling which view I am on and what I can switch too.. This is being declared in my appdelegate.m file as per the xcode template.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController 开发者_StackOverflow= self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

Or their is the area in each viewcontroller where everything gets loaded... Im thinking it might be better to initialize the animation in here.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Super", @"Super");
        self.tabBarItem.image = [UIImage imageNamed:@"SuperIcon"];
    }
    return self;
}

As I have not done alot of animation with views before I am woundering where I could declare this peice of code that will hopefully animate my view change when a UITabBarButton is touched....

[UIView transitionWithView:containerView
           duration:0.2
           options:UIViewAnimationOptionTransitionFlipFromLeft
           animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; 
           completion:NULL];

or have I missed the boat completely and is their somewhere else I should be doing this?


Try the following code in the viewWillAppear method

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                       forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];

This worked for me for a tabBar controller based app.


Try that animation in code in viewWillAppear method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜