如何创建第二个启动画面(在 ios 中的默认启动画面之后)?

How to create a second splash screen (after default splash screen in ios)?

我试图向 iOS 现有项目添加第二个启动画面,这个项目太旧并且使用 xib 的。

所以我打算先显示默认启动画面,然后在登录页面后显示我自己的图像作为启动画面。

这是我目前所做的

在我的 ViewController.m 文件中,我在 UIView 上创建并添加了一个 UIImageView 它可以正常工作,但问题是我还可以看到导航栏和第二个初始屏幕。

我不要那个导航栏。

请帮帮我 代码

ViewController.m   in ViewDidload ()



 self.navigationController.navigationBar.hidden=YES;

    _splash.frame=CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height);
    _splashImg.frame=_splash.frame;
    [self.view insertSubview:_splash aboveSubview:_loginView];
    [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(runMethod) userInfo:nil repeats:NO];
    [self.view addSubview:_splashView];
    [self.view bringSubviewToFront:_splashView];
    UIImageView *img=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"rss2.png"]];
    img.frame=_splashView.frame;
    [_splashView addSubview:img];

试试这个

隐藏导航栏:

[[self navigationController] setNavigationBarHidden:YES animated:YES];

显示它:

[[self navigationController] setNavigationBarHidden:NO animated:YES];

其他

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];   //it hides  

}

-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO];    // it shows
 }

目前没有 'official' 方法来拥有第二个初始屏幕,所以您正在做的就是要走的路。我对您的唯一建议是将自定义初始屏幕视图添加到 window 而不是视图控制器的视图。将它添加到 window(并相应地调整大小)将使您的自定义视图高于一切。您甚至可以创建一个新的 window 并将其放置在 UIStatusBar 级别以获得类似、更清晰的效果。

编辑:添加示例代码

对于最简单的解决方案

UIWindow *window = [UIApplication sharedApplication].delegate.window;
_splash.frame = window.bounds;
[window addSubview:_splash];
...
// later, when you're done
[_splash removeFromSuperview];

对于稍微复杂但更优雅的创建新 window 的解决方案,请阅读 UIWindow documentation

Apple 只允许每个项目有一个启动画面。您可以通过创建新的视图控制器将自定义图像显示为启动画面。说 SplashViewController。在 SplashViewController 的视图上添加一个 imageView 并设置启动图像。

在您想要显示自定义启动画面时加载 SplashViewController

在 SplashViewController 的 ViewDidLoad 中:

- (void)viewDidLoad{
    [[self navigationController] setNavigationBarHidden:YES animated:YES];
    [self performSelector:@selector(loadingNextView) 
           withObject:nil afterDelay:3.0f];
}

加载下一个视图的方法

- (void)loadingNextView{
// write code for pushing VC. 
}

在您的下一个视图控制器的 ViewDidLoad 中显示导航栏

[[self navigationController] setNavigationBarHidden:YES animated:YES];

AppDelegate 中,您将导航控制器设置为根视图控制器,替换为您只需将 UIViewController 创建为根 viewcontroller

几秒钟后,您只需像 performSelector 一样通过将根视图控制器更改为导航控制器,您的问题就已解决。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SplashScreenController *viewCon=[[SplashScreenController alloc]
                                      initWithNibName:@"SplashScreenController"
                                      bundle:nil];
self.window.rootViewController= viewCon;
[self.window makeKeyAndVisible];
[self performSelector:@selector(loadNavigationController) 
           withObject:nil afterDelay:0.2f];
}
-(void)loadNavigationController{
    HomeController *viewCon=[[HomeController alloc]
                                      initWithNibName:@"HomeController"
                                      bundle:nil];

        self.nav=[[UINavigationController alloc]initWithRootViewController:viewCon];
        self.window.rootViewController= self.nav;
}

希望这有助于缓解您的问题。