views:

333

answers:

1

i have a tabbar application. here is my code

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[application setStatusBarHidden:YES animated:NO];
[self showSplashView];
}
- (void)showSplashView {
//If i don't use black view it displays white screen thats look so bad...
   UIView* blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
blackView.backgroundColor = [UIColor blackColor];
[window addSubview:blackView]; // sends [blackView retain]
[blackView release];

splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"MyImage.png"];
    [window addSubview:splashView];
    [window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil ];
[UIView setAnimationDelay:5.0];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:) ];
   splashView.alpha = 0.0;
   splashView.frame = CGRectMake(-60, -60, 440, 600);

   [UIView commitAnimations];

  }
  - (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
UIView* blackView = [[window subviews] objectAtIndex:0];
    [blackView removeFromSuperview];
    [splashView removeFromSuperview];
    [splashView release];
[window addSubview:tabBarController.view];
[window makeKeyWindow];
 }

so my problem is when my application starts first it displays black screen ,after few second it displays my splash image. when splash screen animation finishes again it displays black screen and after few second it displays my view controller.i dont know why it happens.i hope my question is clear. thanks EDIT My expected behavior is as soon as app start it should display my splash screen instead black screen and as soon as splash animation finish it should display my first view controller(which is table view controller with in first tabbar)..

EDIT 2 : *is it something time consuming in this code [window addSubview:tabBarController.view]; how do i do this process in background while my splash screen is running.*

A: 

The first black screen is because you set the animation delay to 5 seconds. Instead of doing that, why don't you spend the time preparing the first view controller, then display the splash animation. Then you can transition to the view controller once the animation is done.

Also, you should have a Default.png that resembles your first screen. Then you wouldn't need to worry about that blackView. If you're really intent on this splash animation stuff, you should make Default.png look like the first frame of the animation.

However, I highly recommend you check out Apple's HIG document. You're really not conforming to best practices here.

Rob Jones
thanks Rob, it just that i have seen many many app having splash screen.and more over my client needs it..
Nnp
i have removed blackview and animation delay , but it still shows black view in beginning and my screen disappear without any delay and it display white screen before my view gets display.can you tell my how do i prepare my view while splash is getting display.
Nnp