iPhone 12 启动图适配 (黑屏问题,已解)

it2025-10-02  2

Xcode 昨天发布了12.1 版本。里面有了iPhone 12 系列模拟器。 跑了一下之前的项目,启动图(LaucnScreen)是黑屏。 分别百度和谷歌了一下 iPhone 12 适配,均没有相关讨论。 在这里起个话题,希望大家能一起在底下评论区讨论。


我们启动图用的是 Storyboard,用一整张背景图片作为启动图,用ImageSet承载不同屏幕尺寸的对应的图片。启动黑屏肯定是因为没有找到对应屏幕尺寸的图片。但是手动给Contents.json加对应的尺寸,ImageSet会报警告。

Contents.json 文件内容如下:

{ "images" : [ { "filename" : "ra-camping-image-updatesiphone 8-7-6-plus-min.jpg", "idiom" : "iphone", "scale" : "3x", "subtype" : "736h" }, { "filename" : "ra-camping-image-updatesiphone 8-7-6-min.jpg", "idiom" : "iphone", "scale" : "2x", "subtype" : "667h" }, { "filename" : "ra-camping-image-updatesiphone-x-min.jpg", "idiom" : "iphone", "scale" : "3x", "subtype" : "2436h" }, { "filename" : "ra-camping-image-updates1242x2688-min.jpg", "idiom" : "iphone", "scale" : "3x", "subtype" : "2688h" }, { "filename" : "ra-camping-image-updates828x1792-min.jpg", "idiom" : "iphone", "scale" : "2x", "subtype" : "1792h" }, { "filename" : "ra-camping-image-updates-1536x2048-min-1.jpg", "idiom" : "ipad", "scale" : "1x" }, { "filename" : "ra-camping-image-updates-1536x2048-min.jpg", "idiom" : "ipad", "scale" : "2x" } ], "info" : { "author" : "xcode", "version" : 1 } }

对应的 ImageSet 展示如下:


2020-10-27 更新

启动图黑屏问题已经解决。

在 iPhone 12 以前,content.json中配置好相应的屏幕尺寸之后(如上),Xcode 会自动匹配相应的设备。而到目前为止,Xcode 12.1 不会对iPhone 12,iPhone 12 Pro, iPhone 12 Pro Max 这三个机型做自动精准匹配。

所以,只能加入通用 2X、3X 图。

具体做法:

选中对应的imageSet,展开右侧栏,勾选 “Universal”;中间区域会多出一组 Universal 的图片位置,拖入对应的图片;在手机或模拟器上卸载之前的APP,如果是模拟器的话关掉模拟器,清理Xcode缓存,重新编译。

注意:LaunchScreen有缓存不更新是iOS已知问题,所以一定要手动清理掉所有缓存,否则看不到自己想要的效果,浪费很多时间。

更新后的imageSet如下:

最新回复(0)