1

I'd like to make a "splash screen" while starting the iPad app: the Default-[Landscape|Portrait]~ipad.png is shown while starting, afterwards I'd like to add the same image by myself and let it fade out.

The problem is the orientation during applicationDidFinishLaunching; I've got problems to determine to correct image and add it to UIWindow (which seems to be in portrait).

How's it possible to add a fullscreen-image during launch and then let it fade out?

Thank you very much!

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • Note that it is considered bad practice, and actively discouraged by Apple, as stated in the UI Guidelines, to use a "splashscreen". You're supposed to show either a screenshot of the last state or a picture of the most probable state of the application, to give a sense of loading speed and reduce user anxiety, and then immediately move into "active mode". – Kheldar Sep 06 '11 at 22:21

2 Answers2

2

You can add flashView to your RootViewController.view in viewDidLoad:

flashView = [...]; // save reference to this object
flashView.alpha = 1.0;
[self.view addSubview:flashView];

And after applicationDidFinishLaunching animate alpha property to 0.0 in RootViewController's viewDidAppear:

NSTimeInterval duration = 1.0;
int curve = UIViewAnimationCurveLinear;

 // Setup the animation
[UIView beginAnimations:@"splash fade out" context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];

// change alpha
flashView.alpha = 0.0;

// Commit the changes
[UIView commitAnimations];
Nekto
  • 17,837
  • 1
  • 55
  • 65
  • yes, but how to get the orientation in viewDidLoad? Both, the device and self.interfaceOrientation tell me that I'm starting in landscape, which is wrong... – swalkner Sep 06 '11 at 13:11
1

Your problem with orientation during application:didFinishLaunchingWithOptions: is expected behavior; see Get launch orientation of iPad app for a previous question on exactly this topic.

The best solution is to have your root view controller handle displaying the splash screen, or present the splash screen using a modal view controller with UIModalTransitionStyleCrossDissolve. That way you can react to the normal view rotation events and change the splash screen image as needed.

Or you may be able to read UIDevice's orientation property, but it is certainly possible that this too won't be updated (even if you call beginGeneratingDeviceOrientationNotifications from application:didFinishLaunchingWithOptions:) until too late.

Community
  • 1
  • 1
Anomie
  • 92,546
  • 13
  • 126
  • 145
  • but I don't manage it to get the correct orientation... it's always telling me that I'm in portrait, although I'm starting in landscape... – swalkner Sep 06 '11 at 13:12
  • 1
    @swalkner: Did you read the linked answer? Apple documents that the orientation will be portrait during `application:didFinishLaunchingWithOptions:`. At some point after that method returns, the normal UIViewController rotation mechanism will be used to rotate your interface to the actual orientation. Which is why I suggest that you display your splash screen from a UIViewController and use the normal view rotation events to adjust your image for the orientation as needed. – Anomie Sep 06 '11 at 14:24