Monday 29 April 2013

Adding Animation for loading screen

Hi Team,
I am sharing the source code of adding animation for loading image when the application is being launched.


-(void)fadeSplashView{
    
    splashView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = LOADINGIMAGE;
    splashView.animationImages = LOADINGIMAGES;
    splashView.animationDuration = 1;
    splashView.animationRepeatCount = -1;
    [splashView startAnimating];
    
    [self.window addSubview:splashView];
    [self.window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:3];
    [UIView setAnimationDelay:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(removeSubView)];
    splashView.alpha = 0.0;
    [UIView commitAnimations];
    
    //Adding activity indicator on splash view
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.color = [UIColor blackColor];
    indicator.alpha = 1.0;
    indicator.center = CGPointMake(150, 390);
    indicator.hidesWhenStopped = NO;
    [splashView addSubview:indicator];
    [indicator startAnimating];
}

-(void)removeSubView{
    [splashView removeFromSuperview];
}

Create UIImageView object in your AppDelegate.h file and Call "FadeSplashView" method in your "didFinishLauching" method of your AppDelegate.m file.

Here, i have prepared a macro LOADINGIMAGES for array of images.
For array of images that are for animating the loading screen, you should prepare the images according to your loading image.

Please send the comments if you have any queries..
Thank you




No comments:

Post a Comment