Reputation: 121
I have successfully finished my app after months of coding. Now I'm trying to add the initial Splash Screen images to my app. How do i proceed? I have two images: one is the company logo and the other is the app logo (these splash screens are to hide the loading time). I have looked every where for an possible answer, but ended up with no solution. When i name a single pic Default-Landscape.png and run the Ipad App - The image is showing until the main view controller loads up, but I want the first image to be displayed for 1 second and fade out to the second image which will also be displayed for 1 second after which the main view controller appears(the original application page).
I have checked various answers, but none seems to work - Xcode 4 and iPad2 splash screen issue Setting splash images for portrait and landscape mode - IPad etc..
Here is my code for the same - AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSArray *docDir=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath=[docDir objectAtIndex:0];
databasePath=[docPath stringByAppendingPathComponent:@"something.sqlite"];
//databasePath1=[docPath stringByAppendingPathComponent:@"something.sqlite"];
NSString *bundlePath=[[NSBundle mainBundle]pathForResource:@"something" ofType:@"sqlite"];
NSFileManager *mngr=[NSFileManager defaultManager];
if ([mngr fileExistsAtPath:databasePath]) {
NSLog(@"File Exists");
}
else
{
[mngr copyItemAtPath:bundlePath toPath:databasePath error:NULL];
NSLog(@"File Created");
}
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
How should I proceed now? Should I create a new class like (splashScreen 1 and splashScreen 2) with uiImageView and change the didFinishLaunchingWithOptions method? Any help would be greatly appreciated.
Updated: 30 May 2013
Appdelegate.h
#import <UIKit/UIKit.h>
#import "sqlite3.h"
#import "FBInteract.h"
#import "splashScreen1.h"
sqlite3 *dbHandler;
NSString *databasePath;
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *naviObj;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) UINavigationController *naviObj;
@end
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
splashScreen1 *splashScreen1PageObj=[[splashScreen1 alloc]init];
self.naviObj = [[UINavigationController alloc]initWithRootViewController:splashScreen1PageObj];
self.window.rootViewController = self.naviObj;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
[self.window makeKeyAndVisible];
return YES;
}
splashScreen1.h and splashScreen2.h
#import <UIKit/UIKit.h>
#import "splashScreen2.h"
@interface splashScreen1 : UIViewController
{
IBOutlet UIImageView *imgObjSplashImage; // IBOutlet UIImageView *objSplashImage; - in splashScreen2.h
}
-(void)hideSplash;
-(void)navigationToMain;
-(void)showSplash;
@end
splashScreen1.m and splashScreen2.m
- (void)viewDidLoad
{
// Do any additional setup after loading the view from its nib.
[NSTimer scheduledTimerWithTimeInterval:1.2 target:self selector:@selector(showSplash) userInfo:nil repeats:NO];
self.navigationController.navigationBarHidden=YES;
[imgObjSplashImage setAlpha:0]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[super viewDidLoad];
}
-(void)showSplash{
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.2];
[imgObjSplashImage setAlpha:1]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[UIImageView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:2.4 target:self selector:@selector(hideSplash) userInfo:nil repeats:NO];
}
-(void)hideSplash{
[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.4];
[imgObjSplashImage setAlpha:0]; //objSplashImage instead of imgObjSplashImage in splashScreen2
[UIImageView commitAnimations];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(navigationToMain) userInfo:nil repeats:NO];
}
#pragma mark
#pragma mark - Navigation Coding
-(void)navigationToMain {
//[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:NO completion:Nil];
ViewController *ViewControllerPageObj=[[ViewController alloc]init];
[self.navigationController pushViewController:ViewControllerPageObj animated:NO];
[ViewControllerPageObj release];
//[self presentViewController:ViewControllerPageObj animated:NO completion:Nil];
}
-(void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBarHidden=YES;
}
The problem is ViewController(main ViewController) is not loading...I'm getting error saying "message sent to deallocated instance" in viewDidLoad part of ViewController.m
RootViewController -> splashScreen1 -> splashScreen2 is working fine(with all the animation fading in and out) but the final ViewController is not loading..
Upvotes: 1
Views: 730
Reputation: 13860
For this you definitely want another VC, lets call it StartViewController. Add there an imageView, block rotation and setTimer:
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(moveOnAndChangeVC:) userInfo:nil repeats:NO];
and if you develop NavigationControl app you should also change rootVC for example:
+(void)replaceRootVCWithVC:(id)vc {
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[[sharedAppDelegate navigationController] viewControllers]];
if(![viewControllers isEmpty])
[viewControllers replaceObjectAtIndex:0 withObject:vc];
else
[viewControllers addObject:vc];
[[sharedAppDelegate navigationController] setViewControllers:viewControllers];
}
EDIT:
You should change in your appDelegate line with initializer:
self.viewController = [[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil] autorelease];
This should call your VC as a rootVC.
Then in StartViewController.m you should recognize device (this is a iPad only app, right? not universal) and orientation:
+(NSString*)recognizeDeviceAndOrientation {
NSMutableString * returnString;
if([StartViewController deviceInterfaceOrientation] == UIInterfaceOrientationLandscapeLeft || [StartViewController deviceInterfaceOrientation] == UIInterfaceOrientationLandscapeRight) {
returnString = @"Default-Landscape";
} else {
returnString = @"Default-Portrait";
}
if([UIScreen mainScreen].scale == 2.0)
return [NSString stringWithFormat:@"%@%@",returnString,@"@2x"];;
else
return returnString;
}
+(UIInterfaceOrientation)deviceInterfaceOrientation {
return [[UIApplication sharedApplication] statusBarOrientation];
}
This will return you a string with DefaultScreen name with proper orientation. If you handling only one orientation forget about it.
Then in viewDidLoad you add imageView:
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[StartViewController recognizeDeviceAndOrientation]] autorelease];
[imageView setFrame:self.frame];
[imageView setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:imageView];
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(moveOnAndChangeVC:) userInfo:nil repeats:NO];
}
This will call a timer and set imageView.
-(IBACtion)moveOnAndChangeVC:(id)sender {
//if you using navigation app
ViewController *vc = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
[self.navigationController pushViewController:vc animated:NO];
}
This will work. And then if you want to get rid of "back button" just change a rootView Controller like i said in the beginning. Do it in your ViewController class.
Upvotes: 1