How to add animated splash screen in our application - iphone

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];
}

Related

fade out image Animation in iphone [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
iphone fading of images
How can implement fading out animation in to a set of images(array of images). Images will appear one by one. when i using the code given below it will show only a simple slide show.
NSArray *imagearray = [NSArray arrayWithObjects:
[UIImage imageNamed:#"image1.png"],
[UIImage imageNamed:#"imag2.png"],[UIImage imageNamed:#"imag3.png"],[UIImage imageNamed:#"imag4.png"],[UIImage imageNamed:#"imag5.png"],[UIImage imageNamed:#"imag6.png"],[UIImage imageNamed:#"imag7.png"],nil];
imageview.animationImages=imagearray;
imageview.animationDuration = 10.00;
imageview.animationRepeatCount = 0;
[imageview startAnimating];
How can I implement the fading effect?
animate the alpha property of the view:
[UIView animateWithDuration:5 animations:^{
imageview.alpha = 0;
}];
Please visit this stack overflow question its iphone fading of images
- (void)viewDidLoad {
imgView.animationImages=[NSArray arrayWithObjects:
[UIImage imageNamed:#"lori.png"],
[UIImage imageNamed:#"miranda.png"],
[UIImage imageNamed:#"taylor.png"],
[UIImage imageNamed:#"ingrid.png"],
[UIImage imageNamed:#"kasey.png"],
[UIImage imageNamed:#"wreckers.png"], nil];
imgView.animationDuration=20.0;
imgView.animationRepeatCount=0;
[imgView startAnimating];
[self.view addSubview:imgView];
[imgView release];
//The timers time interval is the imageViews animation duration devided by the number of images in the animationImages array. 20/5 = 4
NSTimer *timer = [NSTimer timerWithTimeInterval:4.0
target:self
selector:#selector(onTimer)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[timer fire];
[super viewDidLoad];
}
//It is important that the animation durations within these animation blocks add up to 4
//(the time interval of the timer). If you change the time interval then the time intervals
//in these blocks must also be changed to refelect the amount of time an image is displayed.
//Failing to do this will mean your fading animation will go out of phase with the switching of images.
-(void)onTimer{
[UIView animateWithDuration:3.0 animations:^{
imgView.alpha = 0.0;
}];
[UIView animateWithDuration:1.0 animations:^{
imgView.alpha = 1.0;
}];
}

Adding activityindicator on Default image - code given

I have an imaged name Default.png. This will load when the application is launching. Now i need to add an activity indicator to it. So it will spin and make the app look nice.
We know that we can't add any UI Components when the app is loading. So i thought to add the UIActivityIndicator in the didFinishLaunchingWithOptions method in the App delegate.
These are the steps i followed.
i added a view
added the default.png
added activity indicator
then
[window addSubView:view];
But nothing hapence.
Help how to write the code for this ?
You're on the right track, but you do need to add another UIView to your window (not another UIViewContoller, necessarily) temporarily. I do this sort of thing often. Here's some code that would be appropriate for your applicationDidFinishLaunching:withOptions: method:
[window makeKeyAndVisible]
...
// Create and show an overlay view with a spinner
UIImage *defaultImage = [UIImage imageNamed:#"Default.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:defaultImage];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
// Position the spinner appropriately for our splash image so it's not obscured
CGRect frame = spinner.frame;
frame.origin.x = imageView.frame.size.width / 2 - frame.size.width / 2;
frame.origin.y = imageView.frame.size.height / 5 * 4 - frame.size.height / 2;
spinner.frame = frame;
[spinner startAnimating];
[spinner setHidesWhenStopped:YES];
startupView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[startupView addSubview:imageView];
[imageView release];
[startupView addSubview:spinner];
[spinner release];
[window addSubview:startupView];
The ivar startupView belongs to the app delegate, and later in the startup sequence another method removes it gracefully by fading it from view:
UIActivityIndicatorView *spinner = [[startupView subviews] lastObject];
[spinner stopAnimating];
[UIView animateWithDuration:1.0
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^(void) {
startupView.alpha = 0.0;
} completion:^(BOOL finished) {
[startupView removeFromSuperview];
[startupView release];
}];
It's worth mentioning that splash screens like this are not the "recommended" startup screen in Apple's view. But they do not seem to reject apps that have them.
I think that you wanna do a "custom splash screen" isnt it?
You cannot add the activity indicator in this way!
You need add a view controller, and at this view controller do stuff that you need with activity indicator!

Within a UITableView cell, how can I lazy-load images which fade in?

How can I lazy load images in a UITableView cell, with a fade-in effect when the image is loaded?
SDImageWeb is a pretty good library which does what you need. It even has image cache, so once the images are downloaded, then next time they are picked from local flash memory.
What this does not do is fadeIn effect. But this is pretty easy to add, with UIView animations.
So to asynchronously download an image,
[imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]];
thats all..
To Put in fadein animation.
- (void)fadeInLayer:(CALayer *)l
{
CABasicAnimation *fadeInAnimate = [CABasicAnimation animationWithKeyPath:#"opacity"];
fadeInAnimate.duration = 0.5;
fadeInAnimate.repeatCount = 1;
fadeInAnimate.autoreverses = NO;
fadeInAnimate.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimate.toValue = [NSNumber numberWithFloat:1.0];
fadeInAnimate.removedOnCompletion = YES;
[l addAnimation:fadeInAnimate forKey:#"animateOpacity"];
return;
}
To call this - [self fadeInLayer: imageView.layer];
This should do the trick. This animates, your image from alpha 0 to 1 in 0.5 seconds ! To give the wonderful fade in animation.
You are reffering to Asynchronous images. There is a great article available at: http://www.markj.net/iphone-asynchronous-table-image/
Within the connectionDidFInishLoading just put the later after this
UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];
//Paste below code here
to fade it in:
//Paste following here
imageView.alpha = 0.0f;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
imageView.alpha = 1.0f;
[UIView commitAnimations];

Move image from left to right

In my application after the view load, an image should appear from left to right.
I am writing this code in in viewdidload or viewwillappear:
UIImage *image = [UIImage imageNamed:#"PG05(REV).jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
for (int i=-1024; i<=0; i++) {
NSLog(#"i: %d",i);
sleep(5);
imageView.frame = CGRectMake(i,0, 1024, 768);
NSLog(#"done");
[self.view addSubview:imageView];
}
[imageView release];
But problem is that, before loading view it executes the above code than loads the view, so that it seems that view loaded and a static image is there.
But my requirement is that first view load completely then image should display from left to right.
Please help me out.
First of all, you should not call the -(void)addSubview: inside your for loop. You just need to call it once.
Secondly, if you want to animate your imageView from left to right, UIView class provides great functionalities for this using blocks.
Your code should look like this :
UIImage *image = [UIImage imageNamed:#"PG05(REV).jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(-1024, 0, 1024, 768);
[self.view addSubview:imageView];
[imageView release]; //Your imageView is now retained by self.view
//Animation
[UIView animateWithDuration:2.0
animations:^(void) {
imageView.frame = CGRectMake(0, 0, 1024, 768);
}];
The animateWithDuration: method will handle the animation timer for you, just set the duration argument according to your needs.
You can use a function and call it using timer method.
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(moveImage) userInfo:nil repeats:NO];
-(void)moveImage
{
//Your condition
}
This is a job for UIView animations.
Put your imageView down at -1024 left, then go:
[imageView animateWithDuration:5 animations:^{
[imageView.frame = CGRectMake(0,0, 1024, 768)];
}];
Ta-da! A five second animation of your image sliding to the right.
Check out the animation methods of UIView (of which UIImageView is a subclass):
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

Creating a "loading..." view using iPhone SDK

How to create that black/gray modal popup kind of view that many apps use, when some long pending operation is in progress?
Like when using location based services, loading a webpage, the screen goes dim and there is a modal view showing a spinning icon "Please wait..."
Example in the following screenshot:
This is actually the undocumented (in 2.2.1 anyway) UIProgressHUD. Create one like this:
In your .h:
#interface UIProgressHUD : NSObject
- (UIProgressHUD *) initWithWindow: (UIView*)aWindow;
- (void) show: (BOOL)aShow;
- (void) setText: (NSString*)aText;
#end
In your .m:
- (void) killHUD: (id)aHUD
{
[aHUD show:NO];
[aHUD release];
}
- (void) presentSheet
{
id HUD = [[UIProgressHUD alloc] initWithWindow:[contentView superview]];
[HUD setText:#"Doing something slow. Please wait."];
[HUD show:YES];
[self performSelector:#selector(killHUD:) withObject:HUD afterDelay:5.0];
}
If you want to avoid undocumented api you can also take a look at MBProgressHUD. It's similar to UIProgressHUD and even has some additional features.
I think the simplest (a few lines of code), fully documented and most beautiful way is to use the UIAlertView with a UIActivityIndicatorView:
http://iosdevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html
(source: iosdevelopertips.com)
If you add a UIView as a subview of the main window it will cover the entire UI. Make it partially transparent and partially translucent and it will look like a popup.
This example shows how to fade the Default.png splash screen, starting with that it's pretty straightforward to add a couple methods to your application delegate (that has a pointer to the main window) to present and dismiss the progress view.
Take a look at the Wordpress iPhone app (http://iphone.wordpress.org/) for an example of how to do this without using any undocumented API's.
I use LoadingHUDView for this purpose, and it works always.
get LoadingHUDView.m and LoadingHUDView.h and do the following in your base class (or whatever)
#pragma mark ActivityIndicator Methods
-(void) showModalActivityIndicator:(NSString *)message
{
loadingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]retain];// origional
//loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; //testing
loadingView.backgroundColor = [UIColor grayColor]; //[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3];
LoadingHUDView *loadHud = [[LoadingHUDView alloc] initWithTitle:message];
loadHud.center = CGPointMake(160, 290);
[loadingView addSubview:loadHud];
[loadHud startAnimating];
[loadHud release];
[loadingView setAlpha:0.0];
[self.tableView addSubview:loadingView];
[UIView beginAnimations:#"fadeOutSync" context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[loadingView setAlpha:0.5];
[UIView commitAnimations];
}
-(void) hideModalActivityIndicator {
if (loadingView) {
[UIView beginAnimations:#"fadeOutSync" context:NULL];
[UIView setAnimationDidStopSelector:#selector (removeTranparentView) ];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[loadingView setAlpha:0];
[UIView commitAnimations];
}
}
-(void)removeTranparentView
{
[loadingView removeFromSuperview];
[loadingView release];
loadingView = nil;
}
HOPE THIS HELPS.
thank you
In XIB file, place UIView and UIActivityIndicatorView.
Set ActivityIndicatorView Property SetAnimated to Yes.
#property (retain, nonatomic) IBOutlet UIView* m_LoadingView;
While Starting long operations, Add the LoadingView to the view
m_LoadingView.layer.cornerRadius = 10;
m_LoadingView.center = self.view.center;
[self.view addSubview:m_LoadingView];
After completing the process, Remove LoadingView from super view.
[m_LoadingView removeFromSuperView];