Archana Chaurasia
Archana Chaurasia

Reputation: 1396

How to add animated splash screen in our application

How to add animated splash screen in our application.

Upvotes: 8

Views: 21454

Answers (4)

TheTiger
TheTiger

Reputation: 13364

Old Answer:

Well this is not possible yet. You can not make any Animation on Splash Screen. But you can make it via UIViewController class which will look like a Splash Screen. Remove the default.png image from your project by which user cant see the Default Splash Screen. Then in your first ViewController class you can make an animation using an array of images as was told above already. And in viewDidLoad: method make a NSTimer then hold the View according to you. After finish the time limit of NSTimer navigate your next ViewController view.

Edit:

I found an alternative solution to make it animated. We can show a .gif image in webView and it looks perfect!

NSString *imagePath = [[NSBundle mainBundle] pathForResource: @"animated" ofType: @"gif"];
NSData *data = [NSData dataWithContentsOfFile:imagePath];
[self.webView setUserInteractionEnabled:NO];
[self.webView loadData:data MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

Make this view as a rootView of your app and after few delay navigate your next View. Remember make its userIntractionEnabled: false i.e. user cant scroll it.

Full description see here Animated Splash Screen in iPhone

Upvotes: 3

Varun Mehta
Varun Mehta

Reputation: 1753

Its very simple...I had used it in to begin my app with splashView.Hope it vil help you.... In AppDelegate.m:

application didFinishLaunchingWithOptions:

UIImage* image=[UIImage imageNamed:@"splash.jpg"];
splashView=[[UIImageView alloc]initWithImage:image];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[self performSelector:@selector(removeSplash) withObject:self afterDelay:2];
[window makeKeyAndVisible];

To remove splashView:

-(void)removeSplash{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:YES];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationDelegate:self];
    [splashView removeFromSuperview];
    [UIView commitAnimations];
    [window addSubview:viewController.view];
}

Upvotes: 3

DSRawat
DSRawat

Reputation: 107

I do this by creating an array of images because gif is not supported format

Just add image frames of your movieclip for eg: {Splashbackground1,Splashbackground2,Splashbackground3 are sequence of images}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    // create the view that will execute our animation for elephant
    CGRect splashscreenmovieclipframe = CGRectMake(0.0f,0.0f,480.0f, 320.0f); //set co-ordinate here i use full screen
    splashscreenmovieclip = [[UIImageView alloc] initWithFrame:splashscreenmovieclipframe];

    // load all the frames of our animation
    splashscreenmovieclip.animationImages = [NSArray arrayWithObjects:   
                                    [UIImage imageNamed:@"Splashbackground.png"],
                                             [UIImage imageNamed:@"Splashbackground1.png"],
                                             [UIImage imageNamed:@"Splashbackground2.png"],
                                             [UIImage imageNamed:@"Splashbackground3.png"],
                                             nil];

    // all frames will execute in 1.75 seconds
    splashscreenmovieclip.animationDuration =7;
    // repeat the annimation forever
    splashscreenmovieclip.animationRepeatCount = 0;
    // start animating
    [splashscreenmovieclip startAnimating];
    // add the animation view to the main window
    [self.view addSubview:splashscreenmovieclip];

    [NSTimer scheduledTimerWithTimeInterval:7.0f target:self selector:@selector(Gotomainmenuview:) userInfo:nil repeats:NO];

    [super viewDidLoad];
}


- (void)Gotomainmenuview:(NSTimer *)theTimer 
{
    // write your code here for counter update 
    [splashscreenmovieclip removeFromSuperview];
    newclasstojump *mmvc=[[newclasstojump alloc]initWithNibName:@"newclasstojump" bundle:nil];
    [self.view addSubview:mmvc.view];
}

Upvotes: 2

Pragnesh Dixit
Pragnesh Dixit

Reputation: 449

You can use sequence of images, here is code:

for(NSInteger i=1;i<=totalImages;i++){
        NSString *strImage = [NSString stringWithFormat:@"Activity_%d",i];
        UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:strImage ofType:@"png"]];
        [imageArray addObject:image];
    }
    splashImageView.animationImages = imageArray;
    splashImageView.animationDuration = 0.8;

and just call startAnimation and endAnimation method of UIImageView.

Upvotes: 4

Related Questions