You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中如何在Xcode里移除或隐藏LaunchScreen.storyboard

在React Native环境中彻底清理Xcode里的LaunchScreen.storyboard配置

你已经移除了LaunchScreen.storyboard文件,接下来需要清理相关配置并设置自定义启动屏,步骤如下:

1. 移除Info.plist中的启动屏配置

  • 打开项目的Info.plist文件:
    • 若用Xcode可视化编辑,找到Launch screen interface file base name这一项,直接删除;
    • 若用源码编辑,删除以下代码段:
      <key>UILaunchStoryboardName</key>
      <string>LaunchScreen</string>
      

2. 配置自定义启动屏

如果要使用自定义图片或纯代码启动屏,可在AppDelegate中添加临时启动视图逻辑,直到React Native加载完成:

Objective-C 示例

在AppDelegate.m中:

  1. 先在类声明中添加属性:
    @interface AppDelegate ()
    @property (nonatomic, strong) UIWindow *launchWindow;
    @end
    
  2. 在didFinishLaunchingWithOptions方法中添加:
    // 创建临时启动窗口
    self.launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    UIImageView *launchImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CustomLaunchImage"]];
    launchImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.launchWindow addSubview:launchImageView];
    [self.launchWindow makeKeyAndVisible];
    
    // React加载完成后隐藏(或设置延迟隐藏)
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.5 animations:^{
            self.launchWindow.alpha = 0.0;
        } completion:^(BOOL finished) {
            self.launchWindow = nil;
        }];
    });
    

Swift 示例

在AppDelegate.swift中:

  1. 添加属性:
    private var launchWindow: UIWindow?
    
  2. 在application(_:didFinishLaunchingWithOptions:)方法中添加:
    // 创建临时启动窗口
    launchWindow = UIWindow(frame: UIScreen.main.bounds)
    let launchImageView = UIImageView(image: UIImage(named: "CustomLaunchImage"))
    launchImageView.contentMode = .scaleAspectFill
    launchWindow?.addSubview(launchImageView)
    launchWindow?.makeKeyAndVisible()
    
    // 延迟隐藏启动视图
    DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
        UIView.animate(withDuration: 0.5) {
            self.launchWindow?.alpha = 0.0
        } completion: { _ in
            self.launchWindow = nil
        }
    }
    

3. 清理项目缓存

  • 执行pod install(项目使用CocoaPods时);
  • 在Xcode中按Cmd + Shift + K清理Build Folder;
  • 重新编译项目,确保配置生效。

内容的提问来源于stack exchange,提问作者Asad Kabir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 05:50:35