Monday, May 3, 2010

How to Create Delayed Tab Change

Not sure, if it's a good idea, but this is how you create "smooth" tab view changes:
#pragma mark - TabBar controller delegate
- (void)tabBarController:(UITabBarController*)tbc
  didSelectViewController:(UIViewController*)newSelection
{
    [UIView beginAnimations:@"myTabFade" context:nil];
    [UIView setAnimationDuration:0.5];
    for (UIViewController* vc in tbc.viewControllers)
        vc.view.alpha = (vc==newSelection) ? 1 : 0;
    [UIView commitAnimations];  
}
User will notice something happened as expected and your app will look either stylish or slow, depending on your graphics, UI design and overall implementation.

Be careful, style is not an easy thing to achieve!

1 comment:

  1. Just to record my experience: there can be "weird" timing related problems. New view after tab change can remain blank in cases where view content was updated before tab change ended.

    ReplyDelete