APP启动时候我们经常看到一个启动页面,我知道的有一下两种做法:

  1. LaunchScreen.storyboard 的运用 点击LaunchScreen.storyboard,用IB为LaunchScreen添加一个UIImageView,将UIImageView的image 设置成你想要的图片,为UIImageView 添加约束。如图

IOS10launcher怎么用 ios launcher怎么用_加载

设置LaunchScreen.storyboard为 LaunchScreen.

IOS10launcher怎么用 ios launcher怎么用_重启_02

IOS10launcher怎么用 ios launcher怎么用_加载_03

运行一下看到效果
2. 使用LaunchImage设置LaunchImage

IOS10launcher怎么用 ios launcher怎么用_重启_04

将各个尺寸对应的图片拖进去

IOS10launcher怎么用 ios launcher怎么用_重启_05

IOS10launcher怎么用 ios launcher怎么用_重启_06

IOS10launcher怎么用 ios launcher怎么用_启动页面_07

IOS10launcher怎么用 ios launcher怎么用_启动页面_08

运行一下就可以看到效果了


我们发现启动图片的加载时一下子就过去了,如果想要延长时间可以在appdelegate中添加代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    [NSThread sleepForTimeInterval:3.0];//设置启动页面时间
    return Yes;
}

下面这段是摘录的。swift还没学,先记着。

//Swift code
    //这个是swift得版本的.额,你千万不要自己新增一个方法viewDidLoad哦,你里面有的
    override func viewDidLoad() {
        super.viewDidLoad()
        NSThread.sleepForTimeInterval(3.0)//延长3秒
    }

这两天在运用第一种的过程中,出现了一个bug 。之前的项目是用LaunchScreen.storyboard 的,想要给他换一张启动图,结果一直没法显示到图片,但是可以加载到LaunchScreen。
我在网上搜索了一下这些方法:
1.卸载重新运行

资源的问题,一般如果确定资源没问题,多是资源没加载到手机。

xcode 经常会有这个毛病,一般 clear 工程,删除手机上的APP会解决。

有些时候需要重启xcode ……,重启手机,一般作用不大吧

2.图片格式问题

图片格式要png ,不能将JPG格式的图片强行修改成PNG;图片的分辨率不能太大。

3.修改图片的名称,不要跟修改前的一样。

iOS 解决LaunchScreen中图片加载黑屏问题
出现这个问题具体也不知道原因是什么

解决方法:修改相应的图片文件名,重新使用这个图片即可,问为什么这么做,说实话我也不知道
但我就是这么解决的

以上方式我都尝试过,结果都不行。产生的效果是模拟器可以加载到图片,真机不行。

然后我怀疑是美工给我的图片有问题,自己的工程的路径下P了那张图替换掉。还是不行。

最后我的解决方式是:改用第二种方法。就可以 了。我也不知道为什么T^T。