0

does anyone know if there is a way to tell if the launch storyboard executed? Or is there a way to detect if the launch image was displayed?

Basically my app consists of just one view controller with some views (all created programmatically), plus the launch storyboard which I added to the project recently which seems to be working OK.

The reason why it would be useful for me to know if the launch storyboard happened is that my app is a game which basically consists of a big 2D scene that you can zoom into and pan around using the usual touch gestures. When the game starts for the first time it starts fully zoomed-out and centered on the scene: so that is what the launch image matches. But the player pans around and zooms-in on various things, so when they press the home button they could be zoomed into any part of the picture. So when they touch the app's icon to relaunch, if the launch storyboard happens it needs to put their pan/zoom position back to the initial centered zoomed-out position (otherwise as soon as the app gets going it would appear to the user to suddenly snap from the initial position represented in the launch image to where they were, not giving a smooth user experience).

What I do at the moment is -- if applicationDidEnterBackground: method gets called I assume that when the user relaunches the app, by touching the icon, that the launch storyboard will be executed. But the launch storyboard doesn't always happen after it hibernated via applicationDidEnterBackground:, especially if it is only a few minutes since the user pressed the home button.... and those times when the launch storyboard does not happen I need not inconvenience the player and put them back to the initial zoomed-out centered position, I could just let them carry on at the position they were.

I've not used storyboards before, but as I understand it launch storyboard are a special case where you can't make any connections to code because your app's not actually running yet, so I can't think of a way to set a variable, for example, to show the story board happened.

Anyone got any ideas?

Cheers,

Jon

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jon Z
  • 11
  • 2

1 Answers1

1

Just use the viewDidLoad method provided by the UIViewController. Just override the method in your ViewController and then you can perform the task you want when your View(Storyboard) is loaded. Example:

@implementation MyViewController:UIViewController
-(void)viewDidLoad{
//Insert your code here
}
@end
ok404
  • 352
  • 2
  • 13
  • If you are worried about the order of things getting called, you can check this answer : http://stackoverflow.com/a/15864784/765298 – Losiowaty Nov 30 '15 at 14:13
  • I put an NSLog in viewDidLoad to try you suggestion, but I saw the launch image displayed a couple of times without it calling viewDidLoad after. I'm guessing it will only call viewDidLoad if the app ended via applicationWillTerminate (or if it is the first time it's run). – Jon Z Nov 30 '15 at 15:15