How to add animated splash screen in our application.
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.
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];
}
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
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With