How can I add two splash screen's in my iPhone app? - iphone

I am making an app in which I have put a default.png in the areas provided and added sleep(5); to my app delegate and currently it runs fine.
What I need to do is add more than one image when the app starts, so that I get one splash screen for 2.5 seconds and another one for 2.5 seconds.
How can I show 2 splash screens at start up?

Two splash screens are not possible. Create a viewcontroller with UIImageView filled with second image and show it for 2.5 seconds.

Just simply add your image to your view controller and after 2.5 second, remove it from your view.

You can easily implement your view on top of the main view but in your appDelegate. For example, if you want a splash image that fades out to the main view: (or a default image that seems to fade out: just put the same image on the splash screen and the default screen). This gives you also the right orientation as long as it is the main view's.
Just add it in your
application:(UIApplication *)application didFinishLaunchingWithOptions:
method:
UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:#"your_default_image_or_First.png"]];
[[firstViewController view] addSubview:imageView];
[[firstViewController view] bringSubviewToFront:imageView];
[NSThread SleepForTimeInterval:(2.5)];
[imageView setImage:[UIImage imageNamed:#"your_default_image_or_Second.png"]]
// as usual
[self.window makeKeyAndVisible];
//now fade out splash image
[UIView transitionWithView:self.window duration:1.0f options:UIViewAnimationOptionTransitionNone animations:^(void){imageView.alpha=0.0f;} completion:^(BOOL finished){[imageView removeFromSuperview];}];

Hi please try with following code its really hwlp full for you dear i suggested to use this one.....
-(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil] autorelease];
self.navigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease];
UIImage *image = [UIImage imageNamed:#"Welcome.png"];
if (!image)
{
NSLog(#"Something went wrong trying to get the UIImage. Check filenames");
}
imageView.image = image;
[self.window addSubview:imageView];
[self.window makeKeyAndVisible];
[self performSelector:#selector(removeFirstSplash:) withObject:imageView afterDelay:3];
return YES;
}
-(void)removeFirstSplash:(UIImageView *)oldImageView
{
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease];
UIImage *image = [UIImage imageNamed:#"Splash.png"];
imageView.image = image;
[self.window addSubview:imageView];
[self performSelector:#selector(removeSecondSplash:) withObject:imageView afterDelay:3];
[oldImageView removeFromSuperview];
}
-(void)removeSecondSplash:(UIImageView *)oldImageView
{
[self.window addSubview:self.navigationController.view];
[oldImageView removeFromSuperview];
}

Related

how can i show 2 intro views when the app is launching?

I know if there is a file named Default.png it shows the image automatically.
but, I want to change the image during it showes.
FYI, I have 2 images Default.png and default2.png.
I want to display default2.png after show Default.png.
I tried followed codes, but it didn't work.
What do I have to do?
-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//..................................................................
//self.window bullabulla~
[self performSelectorOnMainThread:#selector(showIntro2View) withObject:nil waitUntilDone:YES];
//[self showIntro2View]; //also tried this, but not work.
[self.window addsubview:tabbarController];
[self.window makeKeyAndVisible];
}
-(void) showIntro2View {
UIImageView *intro2 = [[UIImageView alloc]initwithframe:cgrectmake(0,0,320,460)];
intro2.image = [UIImage imagenamed:#"default2.png"];
[self.window addSubview:intro2];
[self.window bringSubviewToFront:intro2];
[NSThread sleepfortimeinterval:2];
}
In your APP DELEGATE.
Something like this should do the job:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:self.window.bounds] autorelease];
UIImage *image = [UIImage imageNamed:#"NAMEOFYOURSPLASHSCREEN.png"];
imageView.image = image;
[self.window addSubview:imageView];
[self.window makeKeyAndVisible];
[self performSelector:#selector(remove1stSplash:) withObject:imageView afterDelay:5];
return YES;
}
- (void)remove1stSplash:(UIImageView *)1stView {
UIImageView *imageView = ...
[self.window addSubview:imageView];
[self performSelector:#selector(remove2ndSplash:) withObject:imageView afterDelay:5];
[1stView removeFromSuperView];
}
- (void)remove2ndSplash:(UIImageView *)2ndView {
[self.window addSubview:.....
[2ndView removeFromSuperView];
}
EDIT:
Link for a sample project:
Two Splash Screen display in iphone
As you may know, you don't have real influence on how long the Default img is displayed. But you know when it shows and hides. It shows only, when the app runs the first time, the app is not in background or has been terminated after a while of not using it.
The first View Controller that is called, should implement viewWillAppear, as it is something like the last method called before the default image hides. There everything is loaded and you can immediately add a subview to the main window.
I'd do it in 2 different methods like showOverrideDefaultImage and hideOverrideDefaultImage. In the show method you add your own View to the appDelegate window and fire a
[self performSelector:#selector(hideOverrideDefaultImage) withObject:nil afterDelay:2];
In the hide method simply remove your view from superview. Therefore you have to have a valid pointer to this object.
that's it. Don't use NSThread.
Do this:
-(void) showIntro2View
{
UIImageView *intro2 = [[UIImageView alloc]initwithframe:cgrectmake(0,0,320,460)];
intro2.image = [UIImage imagenamed:#"default2.png"];
intro2.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Default.png"],
[UIImage imageNamed:#"default2.png"], nil];
intro2.animationDuration = 2.0f;
intro2.animationRepeatCount = 0;
[intro2 startAnimating];
[self.window addSubview:intro2];
[self.window bringSubviewToFront:intro2];
[NSThread sleepfortimeinterval:2];
}

iPhone Splash Image

Trying to programmatically add a splash image that hangs around for a specified amount of time. I have Default.png already imported into my project, and I see it flicker as the launch image when the simulator launches. I'm not sure how to make Default.png hang around as the splash image.
In AppDelegate.m, inside didFinishLaunchingWithOptions I do the following:
MyViewController *mvc = [[MyViewController alloc] init];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:mvc] autorelease];
[navController setNavigationBarHidden: YES];
MyViewController as you might suspect, is a subclass of UIViewController, and in the loadView method I do the following:
self.mainView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = mainView;
mainView.backgroundColor = [UIColor yellowColor];
Then I created SplashScreenViewController, also a subclass of UIViewController, and in the loadView method I do the following:
splashView = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)] autorelease];
splashView.image = [UIImage imageNamed:#"Default.png"];
Finally, back in AppDelegate I have the following after makeKeyAndVisible:
SplashScreenViewController *splashScreen = [[SplashScreenViewController alloc] init];
splashScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[navController presentModalViewController:splashScreen animated:NO];
I think I'm just stuck understanding how to tie all the UIViewController subclasses together, and how to reference them from AppDelegate (or whether I should even be doing that), etc. Any tips are appreciated. I can clarify if my question is muddy.
You can move this to MyViewController's viewDidLoad
SplashScreenViewController *splashScreen = [[SplashScreenViewController alloc] init];
splashScreen.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[navController presentModalViewController:splashScreen animated:NO];
Or you could do this in you AppDelegate, before makeKeyAndVisible
splashView = [[[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)] autorelease];
splashView.image = [UIImage imageNamed:#"Default.png"];
[self.window addSubview:splashView];
[self.window bringSubviewToFront:splashView];
What's your plan for dismissing the view?

Display a Splash Screen Before Loading the Root Navigation Controller - iPhone

I am new bee in iPhone. I have implmented using some tutorials, a Splash Screen before loading the UIViewController. Now i want to implement a NavigationController in my application and want to display a Splash Screen before it. Since I am new in Iphone so i did not get any tutotrials or guides to make a Splash Screen before loading a Root Navigation Controller.
I have seen many methods in which they over write the Default.png file and so on. I dont want to implement that one. I want a sperate UIView to have my custom Images and text in it and display that UI View as a Splash Screen
can anybody Guide me please.
Thanks in advance
Here you go buddy. Have fun and happy coding....
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Add a splash screen
UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"splash.png"]];
imgv.userInteractionEnabled = YES;
[navigationController.view addSubview:imgv];
[imgv release];
[self performSelector:#selector(removeSplash:) withObject:imgv afterDelay:3.0];
[window addSubview:navigationController.view];
return YES;
}
- (void)removeSplash:(UIImageView *)imageView {
[imageView removeFromSuperview];
}
Use "self.window" to display the splash image first. If u simply write "window", the image will not be displayed and animated in the first view, since the image can't be directly linked to the window in that case. Write the following code in appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
UIImageView *imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"themes.png"]];
imgv.userInteractionEnabled = YES;
[self.navigationController.view addSubview:imgv];
//[imgv release]; If you don't use ARC, uncomment this.
[self performSelector:#selector(removeSplash:) withObject:imgv afterDelay:3.0];
[self.window addSubview:self.navigationController.view];
return YES;
}
- (void)removeSplash:(UIImageView *)imageView
{
[imageView removeFromSuperview];
}

How to insert an UIView (during launch time) that will be used for Core Animation after in the program?

I have a View based application for iPhone/iPod that plays audio, having a VU meter showing the input dB level. This VU meter is animated using Core Animation.
The app runs fine, with the VU meter working great, having just one single View. But now, sadly, that I have inserted a Tab bar controller, to have another View with some internet content, I can't get the VU meter to work on my first View, as before.
The app crashes (receiving the EXC_BAD_ACCESS message) because the UIView (that contains the VU meter .png file for Core Animation) is not being properly inserted during launching time as it did before as a View only application.
Here is my code, in the myAppDelegate.m file:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
PlayerViewController *newController = [[PlayerViewController alloc] initWithNibName: #"PlayerView"
bundle: [NSBundle mainBundle]];
self.viewController = newController;
[newController release];
UIView *controllerView = [self.viewController view];
[self.window addSubview: controllerView];
[self.viewController addBargraphToView: controllerView];
[self.window makeKeyAndVisible];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
And here is my PlayerViewController.m file, where I have the addBargraphToView method containing my image to be inserted. It remains invisible until the VU meter starts working:
- (void) addBargraphToView: (UIView *) parentView {
// static image for showing average level
UIImage *soundbarImage = [[UIImage imageNamed: #"vu-meter.png"] retain];
// background colors for generated image for showing peak level
self.peakClear = [UIColor clearColor];
self.peakGray = [UIColor lightGrayColor];
self.peakOrange = [UIColor orangeColor];
self.peakRed = [UIColor redColor];
levelMeter = [CALayer layer];
levelMeter.anchorPoint = CGPointMake (0.0, 20.0); // anchor to halfway up the left edge
levelMeter.frame = CGRectMake (15, 200, 0, kLevelMeterHeight); // set width to 0 to start to completely hide the bar graph segements
levelMeter.contents = (UIImage *) soundbarImage.CGImage;
peakLevelMeter = [CALayer layer];
peakLevelMeter.frame = CGRectMake (41, 233, 0, kLevelMeterHeight);
peakLevelMeter.anchorPoint = CGPointMake (0.5, 10.0);
peakLevelMeter.backgroundColor = peakGray.CGColor;
peakLevelMeter.bounds = CGRectMake (0, 0, 0, kLevelMeterHeight);
peakLevelMeter.contentsRect = CGRectMake (0, 0, 1.0, 1.0);
[parentView.layer addSublayer: levelMeter];
[parentView.layer addSublayer: peakLevelMeter];
[soundbarImage release];
}
How can I solve this problem? Should I insert the UIView image at some other point, and not during the application's launch time?
Many thanks for your help, dear friends!
Move this call:
[self.viewController addBargraphToView: controllerView];
To -viewDidLoad inside your PlayerViewController implementation:
- (void) viewDidLoad
{
[super viewDidLoad];
[self addBargraphToView: self.view];
}
Edit
OK, I think the problem lies in double adding viewControllers. Make this the content of your application:didFinishLaunchingWithOptions: method:
PlayerViewController *newController = [[PlayerViewController alloc] initWithNibName: #"PlayerView"
bundle: [NSBundle mainBundle]];
self.viewController = newController;
[newController release];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: newController, yourInterntContenViewController, nil];
[self.window addSubview: self.tabBarController.view];
[self.window makeKeyAndVisible];
return YES;

Splash Screen: EXC_BAD_ACCESS after calling dismissModalViewControllerAnimated delayed

I am trying to create a 1-2 second splashcreen for my application using a modal view controller however when i try to dismiss the view my application crashes with a bad access error. So in my application delegate i have:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//create window and show it
window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
window.backgroundColor = [UIColor greenColor];
[window makeKeyAndVisible];
//create the main view controller and add its view to the window
mainViewCtrl = [MainViewController alloc];
[window addSubview:mainViewCtrl.view];
//show splash screen
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"default.png" ofType:nil]];
splashViewCtrl = [[UIViewController alloc] init];
splashViewCtrl.view = [[UIImageView alloc] initWithImage:image];
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
//setup callback to dismiss
[self performSelector:#selector(hideSplash) withObject:nil afterDelay:2.0];
return(true);
}
//hide splash screen callback
- (void)hideSplash {
[[self mainViewCtrl] dismissModalViewControllerAnimated:YES];
}
And this all works perfectly fine except when the hideSplash is called after 2 seconds the application crashes with a EXC_BAD_ACCESS. If i comment out the perform selector line and call the hidesplash immediately after like so:
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
[self hideSplash];
The modal view is properly dismissed. I'm fairly sure this is a memory management problem but i'm not sure exacty what i'm doing wrong here. Does anyone have any ideas of what this could be or how to properly debug this so i can delay the dismissal?
Thanks
This looks weird:
mainViewCtrl = [MainViewController alloc];
Try adding the initialisation call to it.
//show splash screen
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"default.png" ofType:nil]];
splashViewCtrl = [[UIViewController alloc] init];
splashViewCtrl.view = [[UIImageView alloc] initWithImage:image];
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
Change the above to this below:
//show splash screen
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"default.png" ofType:nil]];
splashViewCtrl = [[UIViewController alloc] init];
splashViewCtrl.view = [[UIImageView alloc] initWithImage:image];
[mainViewCtrl presentModalViewController:splashViewCtrl animated:NO];
[mainViewCtrl release]; //Add this line !!!!