How can I display a splash screen for a longer period of time than the default time on an iPhone?
What I did is presented a modalview controller in the initial screen and then dissmiss it after several seconds
- (void)viewDidLoad
{
[super viewDidLoad];
....
saSplash = [storyboard instantiateViewControllerWithIdentifier:@"SASplashViewController"];
saSplash.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController: saSplash animated:NO];
}
-(void) dismissSASplash {
[saSplash dismissModalViewControllerAnimated:NO];
}
Inside your AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Sleep is code to stop the slash screen for 5MoreSeconds
sleep(5);
[self initializeStoryBoardBasedOnScreenSize];
return YES;
}
//VKJ
According to the Apple HIG you should not do that. But if your application needs to do so for definite purpose, you can do:
Write the following line at the first of the "application didFinishLaunchingWithOptions:" method
sleep(//your time in sec goes here//)
;
I have done this as below:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"splashView"];
self.window.rootViewController = viewController;
Note: LaunchScreen is the launch story borad and splashView is the storyboardIdentifier
In Xcode 6.3, you can show the launch screen.xib and even put a indicator on it, first it will show the default launch screen it is replaced by the nib so the user doesn't know it changed and then if everything is loaded hide it :-)
func showLaunchScreen() {
// show launchscreen
launchView = NSBundle.mainBundle().loadNibNamed("LaunchScreen", owner: self, options: nil)[0] as! UIView
launchView.frame = self.view.bounds;
self.view.addSubview(launchView)
// show indicator
launchScreenIndicator = UIActivityIndicatorView(frame: CGRectMake(0, 0, 50, 50)) as UIActivityIndicatorView
launchScreenIndicator.center = CGPointMake(self.view.center.x, self.view.center.y+100)
launchScreenIndicator.hidesWhenStopped = true
launchScreenIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
launchView.addSubview(launchScreenIndicator)
self.view.addSubview(launchView)
launchScreenIndicator.startAnimating()
self.navigationController?.setNavigationBarHidden(self.navigationController?.navigationBarHidden == false, animated: true) //or animated: false
}
func removeLaunchScreen() {
println("remove launchscreen")
self.launchView.removeFromSuperview()
self.launchScreenIndicator.stopAnimating()
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
For stylish splash screen tutorial check out this http://adeem.me/blog/2009/06/22/creating-splash-screen-tutorial-for-iphone/