自适应启动屏幕故事板:有没有办法区分iPad的方向? [英] Adaptive launch screen storyboards: is there a way to differentiate iPad orientations?
问题描述
我正在研究使用情节提要板为我的应用启动图像.该应用程序始终使用较大的照片作为启动图像,该图像也用作第一视图的背景.但是,当应用程序在iPad上横向启动时,图像会有所不同.
因此,在启动屏幕上使用自适应情节提要板时,有什么方法可以区分纵向iPad和横向iPad?因为它是启动屏幕,所以我无法运行任何代码,所以它必须完全通过情节提要完成.
我找到了一种使用间隔视图的解决方案,该视图将正确的图像放置在可见区域中,并将另一个图像移出屏幕(如示例项目. 它适用于iPad和iPhone.
重要的约束条件是
PortraitSpacer.width ≤ 5 × view.width
PortraitSpacer.width ≤ 5 × view.height
LandscapeSpacer.width ≥ 5 × view.width
LandscapeSpacer.width ≥ 5 × view.height
PositionSpacer.width = 5 × view.width
其中view.width
和view.height
是主视图的宽度和高度.
PortraitSpacer
将人像图像放置在5 × min(view.width, view.height)
处,
LandscapeSpacer
将风景图像放置在5 × max(view.width, view.height)
,
并且PositionSpacer
在纵向模式下与PortraitSpacer
的宽度相同,在横向模式下与LandscapeSpacer
的宽度相同.
我们将所有内容乘以5,所以两个图像不会重叠.这适用于满足以下条件的所有设备
5 × min(view.width, view.height) + max(view.width, view.height) ≤ 5 × max(view.width, view.height)
在横向模式下,这意味着
5 / 4 ≤ view.width / view.height
当前所有设备都是这种情况:iPad的宽高比最低,为4:3,但仍大于5:4.
您当然可以在资产目录中为每个设备(iPhone,iPad)配置图像.
I'm investigating the use of a storyboard for launch images for my app. The app has always used a large photo for the launch image, which is also used as the background for the first view. However the image is different when the app is launched in landscape on an iPad.
So is there any way to differentiate between an iPad in portrait and an iPad in landscape when using a an Adaptive storyboard for a launch screen? Because it's a launch screen I can't run any code, it would have to be done completely through the storyboard.
I found a solution using spacer views that position the correct image in the visible area and move the other one off screen (as suggested by David H).
You can't provide different images for different screen sizes (iPhone 4, iPhone X, ...), but if you want different images for iPhone and iPad and different images for portrait and landscape this solution is for you.
I created an example project on github if you want to try it out. It works on iPad and iPhone.
The important constraints are
PortraitSpacer.width ≤ 5 × view.width
PortraitSpacer.width ≤ 5 × view.height
LandscapeSpacer.width ≥ 5 × view.width
LandscapeSpacer.width ≥ 5 × view.height
PositionSpacer.width = 5 × view.width
where view.width
and view.height
are the main view's width and height.
The PortraitSpacer
positions the portrait image at 5 × min(view.width, view.height)
,
the LandscapeSpacer
positions the landscape image at 5 × max(view.width, view.height)
,
and the PositionSpacer
has the same width as PortraitSpacer
in portrait mode and the same width as LandscapeSpacer
in landscape mode.
We multiply everything with 5 so the two images do not overlap. This works for all devices where the following is true
5 × min(view.width, view.height) + max(view.width, view.height) ≤ 5 × max(view.width, view.height)
In landscape mode this would mean
5 / 4 ≤ view.width / view.height
which is the case for all current devices: iPad has the lowest aspect ratio with 4:3 which is still greater than 5:4.
You can then of course configure images per device (iPhone, iPad) in the asset catalog.
这篇关于自适应启动屏幕故事板:有没有办法区分iPad的方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!