如何在没有用户能够看到呈现视图的情况下使用模态视图控制器启动iOS应用程序?

时间:2021-11-29 11:08:18

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.

我已经尝试了很多组合来做这个从app委托,呈现视图控制器的viewDidLoad,有和没有延迟,有和没有动画。

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?

怎么能实现这一目标?

2 个解决方案

#1


6  

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

使用storyboard尝试下面的代码,应用程序以模态视图控制器启动:

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:

从开始视图控制器到模态视图控制器的配置:

如何在没有用户能够看到呈现视图的情况下使用模态视图控制器启动iOS应用程序?

#2


1  

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

如果你的inititalViewController上面有你的启动图像的图片怎么办?

@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];
}];

#1


6  

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

使用storyboard尝试下面的代码,应用程序以模态视图控制器启动:

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:

从开始视图控制器到模态视图控制器的配置:

如何在没有用户能够看到呈现视图的情况下使用模态视图控制器启动iOS应用程序?

#2


1  

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

如果你的inititalViewController上面有你的启动图像的图片怎么办?

@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];
}];