【问题标题】:How to create a second splash screen (after default splash screen in ios)?如何创建第二个启动画面(在 ios 中的默认启动画面之后)?
【发布时间】:2015-07-09 07:25:48
【问题描述】:

我尝试向 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];

【问题讨论】:

  • 为什么要添加为导航控制器的根视图控制器。
  • 请参考我的回答。

标签: ios objective-c uiview uiimageview splash-screen


【解决方案1】:

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

【讨论】:

  • 我的问题是导航栏
  • 您可以根据需要显示和隐藏导航栏。检查我更新的答案。
  • 你能告诉我你在 application:didfinishlaunching 中做了什么吗?
  • 你是如何创建navigationController的。通过代码或故事板。另外请分享您的代码以推送 ViewController。
【解决方案2】:

试试这个

隐藏导航栏:

[[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
 }

【讨论】:

  • 你可以直接把图片放到self.查看为什么你拍的帧太多
  • 我仍然可以看到导航栏
【解决方案3】:

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

编辑:添加示例代码

对于最简单的解决方案

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

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

【讨论】:

    【解决方案4】:

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

    希望这有助于轻松解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多