简体   繁体   English

不同iOS iPhone尺寸的全屏图像

[英]Fullscreen image on different iOS iPhone sizes

I am not ignorant of how many questions exist around the topic, I've read most and haven't been able to find a straight answer to what should be a common thing to do. 我不知道围绕该主题存在多少个问题,我已经读了最多的书,也无法找到应该做的普通事情的直接答案。

How does one handle full screen sized images on on different phone sizes? 如何在不同尺寸的手机上处理全屏尺寸的图像?

Current strategy: 当前策略:

I'm using vectors so the idea is to create 3 vectors (PDF) in 3 different image assets: 我正在使用矢量,因此要在3种不同的图像资源中创建3个矢量(PDF):

  • Name : mypicture-320 Size : 320 x 568 名称 :mypicture-320 尺寸 :320 x 568
  • Name : mypicture-375 Size : 375 x 667 名称 :mypicture-375 尺寸 :375 x 667
  • Name : mypicture-414 Size : 414 x 736 名称 :mypicture-414 尺寸 :414 x 736

Then when I want to get the image i'll do something in code like (pseudo code): 然后,当我想获取图像时,我将使用(伪代码)之类的代码进行操作:

if iPhone5 {
    return mypicture-320
}
else if iPhone6 {
    return mypicture-375
}
else if iPhone6Plus {
    return mypicture-414
}

This feels wrong, like there should be a better way by now using only xcassets. 感觉不对,就像现在应该只使用xcassets来做更好的选择一样。 Am I missing something? 我想念什么吗?

Related question: If I chose not to use vectors then I'll need the following images: 相关问题:如果我选择不使用向量,则需要以下图像:

  • Name : mypicture-320 Scale :@2 ActualSize : 640 x 1136 名称 :mypicture-320 规模 :@ 2 ActualSize:640×1136
  • Name : mypicture-375 Scale :@2 ActualSize : 750 x 1334 名称 :mypicture-375 比例 :@ 2 ActualSize :750 x 1334
  • Name : mypicture-414 Scale :@3 ActualSize : 1242 x 2208 名称 :mypicture-414 比例尺 :@ 3 ActualSize :1242 x 2208

Calling them in the same way as described earlier. 以与前面所述相同的方式调用它们。

How does one handle full screen sized images on on different phone sizes? 如何在不同尺寸的手机上处理全屏尺寸的图像?

By putting a full sized image view on the different phone sizes. 通过在不同尺寸的手机上放置完整尺寸的图像视图 Constraints tie the edges of the image view to the edges of the screen (in effect), so that it fills the screen no matter how big the screen is. 约束将图像视图的边缘绑定到屏幕的边缘(实际上),从而无论屏幕有多大,它都会填充屏幕。 And use of the correct content mode causes the contained image to be resized to match. 使用正确的内容模式会使所包含的图像调整大小以匹配。

If you need the image to stretch/tile in some special way so that it always fills the screen exactly, use a resizable image . 如果您需要以某种特殊方式拉伸/平铺图像以使其始终准确地填满屏幕,请使用可调整大小的图像 With an asset catalog, you can configure this even more powerfully using Slicing than you can in code. 与资产目录相比,您可以使用切片功能比在代码中更强大地进行配置。 For example, the screenshots below show an iPhone 4s and an iPhone 7; 例如,下面的屏幕截图显示了iPhone 4s和iPhone 7。 the image fills the screen on both, despite the great difference in size and aspect ratio. 尽管尺寸和宽高比有很大差异,但图像仍会同时填满屏幕。

在此处输入图片说明

在此处输入图片说明

320 x 568, 375 x 667 and 414 x 736 all have the same ratio of 9:16. 320 x 568、375 x 667和414 x 736的比例均为9:16。

So you can make one vector image of 9 x 16 at @1x and it will be fine. 因此,您可以在@ 1x处制作一张9 x 16的矢量图像,这样就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM