iOS: Animating a View (Sample of hiding a UITabBarController view)

The UIView class has it's animation methods like beginAnimations, commitAnimations,
animateWithDuration, and setAnimationDuration.

You can use this methods to animate such specific view.

Below is an example of hiding a UITabBarController view and retain the non-UITabBar class views.

    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
   
    //    CGRect temp = appDelegate.tabBarController.view.frame;
    //    temp.origin.y += 100;
   
    for(UIView *view in  appDelegate.tabBarController.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(-320, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
        }
    }
   
    [UIView commitAnimations];



or you can also do like this,


    
[UIView animateWithDuration:.7
     animations:^(void) {
        for(UIView *view in  appDelegate.tabBarController.view.subviews)
        {
            if([view isKindOfClass:[UITabBar class]])
            {
                [view setFrame:CGRectMake(-320, view.frame.origin.y, view.frame.size.width, view.frame.size.height)];
            }
            else
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }
        }
     }
     completion:^(BOOL finished) {
         appDelegate.tabBarController.tabBar.hidden = YES;
     }];


Hope this helps!

Comments

Popular posts from this blog

Converting sectors into MB - Useful in understanding the sectors in iostat in Linux

What is Disk Contention?

Installing MySQL from source: Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)