Translate

Friday, July 6, 2012

Splash screen with animation for iPhone

In your YourAppDelegate.h create a reference to a UIImageView and also whip up a method you'll call through code:
@interface YourAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    YourAppViewController *viewController;
    UIImageView *splashView;
}
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context;
Now, in YourAppDelegate.m add the guts of that method and some additional code in your applicationDidFinishLaunching:
- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
 [splashView removeFromSuperview];
 [splashView release];
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
 
 // Make this interesting.
 splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
 splashView.image = [UIImage imageNamed:@"Default.png"];
 [window addSubview:splashView];
 [window bringSubviewToFront:splashView];
 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:2.0];
 [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
 [UIView setAnimationDelegate:self]; 
 [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
 splashView.alpha = 0.0;
 splashView.frame = CGRectMake(-60, -85, 440, 635);
 [UIView commitAnimations];
}
You're done. You could mess with this in other ways, but it makes the whole entry into your application a lot more appealing in my opinion

No comments:

Post a Comment