10

I've tried many combinations of doing this from the app delegate, the presenting view controller's viewDidLoad, with and without delay, with and without animation.

But either the user can see the presenting view controller for a moment, or the modal doesn't get presented.

How can this be achieved?

abc123
  • 8,043
  • 7
  • 49
  • 80

2 Answers2

6

Tried code below with storyboard, app starts with modal view controller:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self.window makeKeyAndVisible];
    [self.window.rootViewController performSegueWithIdentifier:@"modalSegue" sender:self];

    return YES;
}

Segue configuration from start view controller to modal view controller:

enter image description here

LorikMalorik
  • 2,001
  • 1
  • 14
  • 14
  • The modal doesn't present for me here. But maybe it is because I'm using storyboard? How would I do it with storyboard? – abc123 Oct 20 '13 at 17:50
  • **UPD**: Updated answer for storyboards – LorikMalorik Oct 20 '13 at 18:25
  • Tested this on iOS 7, iOS 6 simulators, and iOS 7 device. Thanks! – abc123 Oct 20 '13 at 21:07
  • 1
    I see now what I was missing from my previous attempts. `[self.window makeKeyAndVisible]`. If I remove this line, it doesn't work. Time to read... thanks again. – abc123 Oct 20 '13 at 21:10
  • Reading the docs didn't help me understand why `[self.window makeKeyAndVisible]` is needed. Why does it make a difference? – abc123 Oct 20 '13 at 21:16
  • 1
    There is a warning when you try presenting modal view without this line - `Warning: Attempt to present on whose view is not in the window hierarchy!`. After you call `[self.window makeKeyAndVisible]` `self.window.rootViewController.view` is added to the window hierarchy and modal vc is being presented without warnings. – LorikMalorik Oct 21 '13 at 07:56
  • This doesn't work. In iOS 9 with storyboards (segue kind: `Present modally`) the underlying view is still visible for a couple of tens of milliseconds even if the segue has `Animates` disabled. – Markus Rautopuro Feb 11 '16 at 12:30
1

What if your inititalViewController had a picture of your launch image over it.

@property (nonatomic, weak) IBOutlet UIImageView *launchImage;

Set the launch image before the view appears.

- (void)viewWillAppear
{
    self.launchImage.image = [self launchImage];
}

Here's a link to get the launch image.

Then when you present the modal view controller, remove the launch image.

[self presentViewController:vc animated:NO completion:^{
    [self.launchImage removeFromSuperview];
}];
Community
  • 1
  • 1
Kevin
  • 16,696
  • 7
  • 51
  • 68