Adding activityindicator on Default image - code given - iphone

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!

Related

Load a picture at application startup that can be updated from the net

I would like to start a picture at startup of my iPhone application (like a splash screen). But I would like to check in a spesific xml on the internet if this picture changed. If the picture is not the same I would like to download it locally to avoid downloading it each time.
Do you know how I can do this? do you have a good tutorial?
Thanks
Laurent
Splash-screen animations are really really cool when you know what you're doing. Unfortunately, except for the iPod (and, I suspect, calendar and messages) apps, it is not possible to change the splash screen of your app. So... cheat.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//inits and windows and such
// Make this interesting.
_splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
//make Default.png some boring white or grey color
_splashView.image = [UIImage imageNamed:#"Default.png"];
coloredSplashView_ = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
coloredSplashView_.image = [UIImage imageNamed:#"colored_splash.png"];
[coloredSplashView_ setAlpha:0.0f];
[_window addSubview:_splashView];
[_window addSubview:coloredSplashView_];
[_window bringSubviewToFront:coloredSplashView_];
[UIView animateWithDuration:1.00 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
coloredSplashView_.alpha = 1.0;
//make the splash visible
}completion:^(BOOL finished) {
//my personal touch: make it expand and fade out
[_splashView removeFromSuperview];
[UIView animateWithDuration:1.00 animations:^{
[coloredSplashView_ setTransform:CGAffineTransformMakeScale(1.2, 1.2)];
[coloredSplashView_ setAlpha:0.0f];
}completion:^(BOOL finished){
[coloredSplashView_ removeFromSuperview];
}];
}];
return YES;
}

How to remove navigation bar from splash screen?

I have problem that is in my code i create splash screen for a time interval. When it execute then on the top of view a navigation bar is appeared. Now i want to hide that navigation bar. How i remove for that splash screen?
- (void)loadView {
// Init the view
//CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGRect appFrame = CGRectMake(0, 0, 320, 480);
UIView *view = [[UIView alloc] initWithFrame:appFrame];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
self.view = view;
[view release];
splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"LS.jpg"]];
splashImageView.frame = CGRectMake(0, 44, 320, 460);
[self.view addSubview:splashImageView];
viewController = [[Menu alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.view.alpha = 0.0;
[self.view addSubview:nc.view];
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(fadeScreen) userInfo:nil repeats:NO];}
-(void) onTimer{
NSLog(#"LOAD");
}
- (void)fadeScreen{
[UIView beginAnimations:nil context:nil]; // begins animation block
[UIView setAnimationDuration:0.75]; // sets animation duration
[UIView setAnimationDelegate:self]; // sets delegate for this block
[UIView setAnimationDidStopSelector:#selector(finishedFading)]; // calls the finishedFading method when the animation is done (or done fading out)
self.view.alpha = 0.0; // Fades the alpha channel of this view to "0.0" over the animationDuration of "0.75" seconds
[UIView commitAnimations]; // commits the animation block. This Block is done.
}
- (void) finishedFading{
[UIView beginAnimations:nil context:nil]; // begins animation block
[UIView setAnimationDuration:0.75]; // sets animation duration
self.view.alpha = 1.0; // fades the view to 1.0 alpha over 0.75 seconds
viewController.view.alpha = 1.0;
[UIView commitAnimations]; // commits the animation block. This Block is done.
[splashImageView removeFromSuperview];
}
You can hide the navigation bar by self.navigationController.navigationBar.hidden = YES;
The "Default" Splash Screen:
Using the Default.png image functionality of iOS is a great alternative for Splash Screens. Just add an image named "Default.png"('D' should be uppercase) to your project and the OS will take care of the rest.
In the splash view controller, add this to viewDidLoad.
self.navigationController.navigationBar.hidden = YES;
I would rather add the navigationcontroller's view to the window instead of the splash view controllers view. Also change the frame of the splash image to have a height of 480. You can also go for Default.png as #EmptyStack suggested
In the Info.plist you can add the property "Status bar is initially hidden" to YES and the status bar is gone forever!

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

How to add animated splash screen in our application

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

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