xcode 使用 Launch Screen.xib 模板的真正通用的 iOS 启动屏幕?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30001169/
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
Truly universal iOS launch screen using Launch Screen.xib template?
提问by mr.dog
So, starting with Xcode 6 we have got a new super-useful feature of Launch Screen template
所以,从 Xcode 6 开始,我们有了 Launch Screen 模板的一个新的超级有用的功能
According to it's description it can help create a launch screen that will work correctly on every device/resolution/orientation and we don't have to make a bunch of different screens for different resolutions with Assets Catalog anymore.
根据它的描述,它可以帮助创建一个可以在每个设备/分辨率/方向上正常工作的启动屏幕,我们不再需要使用资产目录为不同的分辨率制作一堆不同的屏幕。
but... I have failed to find any useful tutorial on how to actually use this to make a single launch screen using a single image for all resolutions (only for landscape).
但是......我没有找到任何关于如何实际使用它来制作单个启动屏幕的有用教程,该屏幕使用所有分辨率的单个图像(仅适用于横向)。
I know how to make a UI element centered on all resolutions using constraints, but i can't figure out how to make my UIImage scale to fill screen height on all resolutions. If i just resize my UIImage to fill current screen size selected in Simulated Metrics - it will fill only that one, but will not work with other screen sizes..
我知道如何使用约束制作以所有分辨率为中心的 UI 元素,但我无法弄清楚如何让我的 UIImage 缩放以填充所有分辨率的屏幕高度。如果我只是调整 UIImage 的大小以填充在模拟指标中选择的当前屏幕尺寸 - 它只会填充那个,但不适用于其他屏幕尺寸。
Can somebody give me a clue? how to make UIImage fill entire screen for all resolutions using this Launch Screen template?
有人可以给我一个线索吗?如何使用此启动屏幕模板使 UIImage 以所有分辨率填充整个屏幕?
回答by Steffen D. Sommer
If you simply just want to fill your launch screen with an image in every screen size, you can use leading, trailing, top and bottom constraints between your UIImageView
and the superview. So:
如果你只是想用每个屏幕尺寸的图像填充你的启动屏幕,你可以在你的UIImageView
和超级视图之间使用前导、尾随、顶部和底部约束。所以:
Step 1Add your UIImageView
to your LaunchScreen.xib
and set whatever image it should display.
步骤 1将您的添加UIImageView
到您的LaunchScreen.xib
并设置它应该显示的任何图像。
Step 2Select your newly added UIImageView
and click the "Pin" icon at the bottom right of Interface Builder.
步骤 2选择您新添加的UIImageView
并单击 Interface Builder 右下角的“Pin”图标。
Step 3Select all 4 edges og set the constants to 0. This makes sure that your UIImageView
has 0 points of space to the superview on every edge.
步骤 3选择所有 4 条边 og 将常量设置为 0。这确保您UIImageView
在每条边上都有 0 点空间到超级视图。
It looks like this:
它看起来像这样:
That said, you should consider if this is the way to go. The idea of having a .xib file as a launch screen is really intended to replace the need of having to show full screen launch images. Instead, consider placing whatever elements your launch image contains in the interface builder instead. Also remember that you're (unfortunately) not able to tie any code together with your launch screen .xib file.
也就是说,你应该考虑这是否是要走的路。将 .xib 文件用作启动屏幕的想法实际上是为了取代必须显示全屏启动图像的需要。相反,请考虑将启动图像包含的任何元素放置在界面构建器中。还请记住,您(不幸的是)无法将任何代码与启动屏幕 .xib 文件绑定在一起。
回答by luk2302
You need to add an UIImageView
to view to your xib file and set the constraints to fill the entire screen, e.g. spacing left, right, top and bottom equal to 0. (You already mentioned you can do this, therefore no more instructions regarding this)
您需要在UIImageView
您的 xib 文件中添加一个以查看并设置约束以填充整个屏幕,例如左、右、上和下间距等于 0。(您已经提到您可以这样做,因此没有更多关于此的说明)
Then you inspect your UIImageView
, set your desired image you want to display and choose as view mode
Aspect Fill
然后您检查您的UIImageView
,设置您想要显示的所需图像并选择作为视图mode
Aspect Fill
That way your UIImageView
takes the image and scales it up, keeping it aspect ratio while filling its entire content.
这样你就UIImageView
可以拍摄图像并放大它,在填充整个内容的同时保持纵横比。