ios 如何添加 iPhoneX 启动图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46191522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Add iPhoneX Launch Image
提问by Christian Cerri
Using Xcode Version 9.0 (9A235), I am trying to add a Launch Image for iPhoneX at the requested 2436px × 1125px (landscape). Currently I am using a Storyboard and it looks like this:
使用 Xcode 版本 9.0 (9A235),我尝试在请求的 2436px × 1125px(横向)处为 iPhoneX 添加启动图像。目前我正在使用故事板,它看起来像这样:
'launchimage' is an Image View linked to an Image Set:
“launchimage”是链接到图像集的图像视图:
And the Image Set is as follows:
图像集如下:
The only place I get an iPhoneX sized image is in a Launch Image set:
我得到 iPhoneX 大小图像的唯一地方是在 Launch Image 集中:
But when I try to select a Launch Image in the Image View on the storyboard it can't be selected:
但是当我尝试在情节提要的图像视图中选择启动图像时,无法选择它:
Any help on how to add the correct sized launch image for iPhoneX or is it back to Launch Images? I would prefer the correct sized image, not a stretched one.
有关如何为 iPhoneX 添加正确大小的启动图像或返回启动图像的任何帮助?我更喜欢正确尺寸的图像,而不是拉伸的图像。
UPDATE:
更新:
I would like to explain why I want the image to be exactly the same pixel per pixel. Following the Guidelines in https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/launch-screen/my launch image is a static version of the first page of the App. If the Launch Image is stretched then there is a noticeable switch from Launch Image to First Page. Which sort of defeats the object of the guidelines. Apple recommend using a storyboard launch, but it seems you can't follow their guidelines if you do. Typical, really.
我想解释一下为什么我希望图像每个像素的像素完全相同。遵循https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/launch-screen/ 中的指南,我的启动图像是应用程序第一页的静态版本。如果启动图像被拉伸,则从启动图像到首页会有明显的切换。哪种方式违背了指导方针的目标。Apple 建议使用故事板发布,但如果您这样做,似乎您无法遵循他们的指导方针。典型的,真的。
采纳答案by Christian Cerri
Using Xcode Version 9.1 (9B55), thanks to the answers above (especially Stoull), however my experience is slightly different. My original question was basically: "How to get launch image (in storyboard or LaunchImage) which matches the bg of the first game scene without a rescaling blip on all resolutions?"
使用 Xcode 版本 9.1 (9B55),感谢上述答案(尤其是 Stoull),但我的体验略有不同。我最初的问题基本上是:“如何获得与第一个游戏场景的背景相匹配的启动图像(在故事板或 LaunchImage 中),而不会在所有分辨率上重新缩放?”
I have resolved this and it works using LaunchImage. However, there are complications.
我已经解决了这个问题,它可以使用 LaunchImage 工作。但是,也有一些并发症。
Add a LaunchImage to the Assets folder, then specify it in the project settings:
将 LaunchImage 添加到 Assets 文件夹,然后在项目设置中指定:
Then you would expect to do this:
那么你会期望这样做:
resulting in:
导致:
BUT on Build you get the warning:
但是在 Build 上你会收到警告:
so you need this for the LaunchImage:
所以你需要这个用于 LaunchImage:
resulting in:
导致:
and there is no warning.... and LaunchImage works on all iPhones/iPads.
并且没有警告......并且 LaunchImage 适用于所有 iPhone/iPad。
The image sizes are:
图像大小为:
iPhoneX (iPhone X Landscape iOS 11+) : 2436 x 1125
iPhoneX(iPhone X 横向 iOS 11+):2436 x 1125
Retina HD 5.5" (iPhone Landscape iOS 8,9) : 2208 x 1242
Retina HD 5.5" (iPhone Landscape iOS 8,9):2208 x 1242
2x (iPhone Portrait iOS 7-9) : 640 x 960
2x(iPhone 人像 iOS 7-9):640 x 960
Retina4 (iPhone Portrait iOS 7-9) : 640 x 1136
Retina4(iPhone 人像 iOS 7-9):640 x 1136
1x (iPad Landscape iOS 7-9) : 1024 x 768
1x(iPad 横向 iOS 7-9):1024 x 768
2x (iPad Landscape iOS 7-9) : 2048 x 1536
2x(iPad 横向 iOS 7-9):2048 x 1536
The system is clearly messy and needs a proper revamp by Apple.
该系统显然很混乱,需要 Apple 进行适当的改造。
回答by Stoull
If your used the LaunchImage.launchimage
for Launch, the solution is (in Xcdoe 9.0):
如果您使用了LaunchImage.launchimage
for Launch,则解决方案是(在 Xcdoe 9.0 中):
Select
Assets.xcassets
, right click on middle pane, selectApp Icons & launch Images
->New iOS Launch Image
. Then move the oldLaunchImage.launchimage
images to the new one, and add the image size with1125×2436 px
for the iPhoneX.Also, you can add the following json object to
Contents.json
file which onLaunchImage.launchimage
folder in your old project。Once Xcode refreshes, just drop in a 1125×2436px image. If you need landscape, you can add another with the orientation.
选择
Assets.xcassets
,右键单击中间窗格,选择App Icons & launch Images
->New iOS Launch Image
。然后将旧LaunchImage.launchimage
图像移动到新图像,并添加1125×2436 px
iPhoneX的图像大小。此外,您可以用下列JSON对象添加到
Contents.json
文件,该文件在LaunchImage.launchimage
您的旧project.Once的Xcode刷新文件夹,只是下降的1125×2436px图像。如果您需要横向,您可以添加另一个方向。
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "2436h",
"minimum-system-version" : "11.0",
"orientation" : "portrait",
"scale" : "3x"
}
回答by Glenn
To the 2018 lazy devs like me who has an existing project that has an old version of launchimage(with no iPhoneX variant), here's my solution to support iPhone X - this is a shortcut one for you.
对于像我这样的 2018 年懒惰的开发人员,他们的现有项目有一个旧版本的launchimage(没有 iPhoneX 变体),这是我支持 iPhone X 的解决方案 - 这是给你的捷径。
- Open Assets.xcassetsin your Xcode.
- Right click in your LanchImage then select Show In Finder.
- Open the Contents.json
- Paste the follow codes inside your "images"array.
- 在 Xcode 中打开Assets.xcassets。
- 右键单击您的 LanchImage,然后选择Show In Finder。
- 打开Contents.json
- 将以下代码粘贴到“图像”数组中。
{ "extent" : "full-screen", "idiom" : "iphone", "subtype" : "2436h", "filename" : "ipxportrait.png", "minimum-system-version" : "11.0", "orientation" : "portrait", "scale" : "3x" }, { "extent" : "full-screen", "idiom" : "iphone", "subtype" : "2436h", "filename" : "ipxlandscape.png", "minimum-system-version" : "11.0", "orientation" : "landscape", "scale" : "3x" },
{ "extent" : "full-screen", "idiom" : "iphone", "subtype" : "2436h", "filename" : "ipxportrait.png", "minimum-system-version" : "11.0", "orientation" : "portrait", "scale" : "3x" }, { "extent" : "full-screen", "idiom" : "iphone", "subtype" : "2436h", "filename" : "ipxlandscape.png", "minimum-system-version" : "11.0", "orientation" : "landscape", "scale" : "3x" },
Replace of course the filename with appropriate images. Voila!
当然用适当的图像替换文件名。瞧!
回答by jonaszmclaren
If I understood correctly, you are using a storyboard as a Launch Screen with image view, right?
如果我理解正确,您将故事板用作带有图像视图的启动屏幕,对吗?
If so, in you Launch Screen storyboard select to view as iPhone X:
如果是这样,在您启动屏幕故事板中选择以 iPhone X 的身份查看:
Then add your image view so it fills the entire area like this:
然后添加您的图像视图,使其像这样填充整个区域:
and pin it to the superview with constants of 0. It's important to do this with iPhone X selected, because otherwise you would probably pin to Top Layout Guide, which you don't want to, because it will leave you with a gap at the top.
并将其固定到常量为 0 的超级视图。在选择 iPhone X 的情况下执行此操作很重要,否则您可能会固定到您不想要的顶部布局指南,因为它会给您留下空白最佳。
Your constaints should look like this (pinned to Superview):
您的约束应如下所示(固定到 Superview):
回答by Vlad Khambir
In portrait orientation, the width of the display on iPhone X matches the width of the 4.7" displays of iPhone 6, iPhone 7, and iPhone 8. The display on iPhone X, however, is 145pt taller than a 4.7" display, resulting in roughly 20% additional vertical space for content.
在纵向模式下,iPhone X 上的显示屏宽度与 iPhone 6、iPhone 7 和 iPhone 8 的 4.7" 显示屏的宽度相匹配。然而,iPhone X 上的显示屏比 4.7" 显示屏高 145pt,导致大约 20% 的额外垂直空间用于内容。
Probably, your image is ok, but try to cleaning (cmd + K)and rebuilding the project.
可能你的图像没问题,但尝试清理(cmd + K)并重建项目。
If it does not helps, then remove this image from Xcode and re-add it again by dragging those images into Xcode. And re-build it. It should work.
如果没有帮助,请从 Xcode 中删除此图像,然后通过将这些图像拖到 Xcode 中重新添加它。并重新构建它。它应该工作。
回答by Ketan Parmar
You can keep larger size image as 3x
image in your image set! I mean 1125px × 2436px
is 3x
resolution of 375pt × 812pt
.
您可以3x
在图像集中保留更大尺寸的图像作为图像!我的意思1125px × 2436px
是3x
分辨率375pt × 812pt
。
so, in your image set replace old 3x
image with the image havign size of 1125px × 2436px
and your launchscreen (storyboard or xib) will not stretch i think!
因此,在您的图像集中,用3x
图像 havign 大小替换旧图像,1125px × 2436px
我认为您的启动屏幕(故事板或 xib)不会拉伸!
回答by jonaszmclaren
EDIT:
I wanted to stress, that it's possible to add Launch Image for iPhone X, but @Christian Cerri was asking for adding NORMAL image to Image View in LaunchScreen.storyboard specifically for iPhone X, which is impossible.
编辑:
我想强调的是,可以为 iPhone X 添加 Launch Image,但 @Christian Cerri 要求将 NORMAL 图像添加到 LaunchScreen.storyboard 中的 Image View 中,专门针对 iPhone X,这是不可能的。
Original Answer:
There's no possibility to add an image specifically for iPhone X to asset catalog (because it uses @3x), so you should probably use launch images for that, if you want another image just for iPhone X.
原始答案:
不可能将专门用于 iPhone X 的图像添加到资产目录中(因为它使用 @3x),因此如果您想要另一个仅用于 iPhone X 的图像,您可能应该为此使用启动图像。
回答by Krutika Sonawala
I removed image view from xib and clean derived data & build. Again added plain image view and than set image after setting constraints (leading, trailing, top, bottom) to superview. That worked well.
我从 xib 中删除了图像视图并清理了派生数据和构建。再次添加普通图像视图,然后在将约束(前导、尾随、顶部、底部)设置为超级视图后设置图像。那效果很好。