在全屏的所有方向上呈现相同的图像

发布于 2024-12-05 20:06:02 字数 138 浏览 0 评论 0原文

我只是想知道如何在横向和纵向模式下设置画廊,并在两种模式下正常显示图像(不拉伸或挤压)。我能想到的唯一方法是在两种尺寸下使用相同的图像,这样就可以显示适合方向的图像。这个想法对我来说显得“愚蠢”,所以如果有人知道更好的方法来设置所有方向的图像视图,请给我一些建议

I was just wondering how can I set up a gallery in landscape and portrait mode, and show the images as normal in both modes (not stretched or squashed). The only way I can think of is having the same image in both sizes so it can be shown the one that suits the orientation. This idea appears "dumb" to me so if someone knows a better way to set an image view in all orientations please give me some advices

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暮年慕年 2024-12-12 20:06:02

横向和纵向的长宽比不同。如果您不想拉伸或挤压图像,可以裁剪图像或将其放入信箱中。

裁剪是指不显示整个图像的情况,例如,纵向覆盖整个屏幕的图像将删除顶部和底部。

信箱式是显示整个图像的地方,但图像周围有纯色。例如,以肖像显示的风景图像在图像上方和下方会有黑色区域。

通过在 Interface Builder 中选择正确的内容模式选项,在 iPhone 上执行上述操作相对容易。

您还可以按照您的描述提供不同的图像,但这仅意味着您需要手动裁剪或装箱。

Landscape and portrait are different aspect ratios. If you don't want to stretch or squash the images, you can either crop the image or letterbox it.

Cropping is where you don't show the entire image, for instance an image that covers the entire screen in portrait would have the top and bottom removed.

Letterboxing is where the entire image is shown, but with a solid colour surrounding the image. For instance, a landscape image shown in portrait would have black areas above and below the image.

It's relatively easy to do the above on the iPhone by selecting the correct content mode options in Interface Builder.

You can also supply different images as you describe, but that would just mean that you'd be cropping or letter boxing manually.

泪之魂 2024-12-12 20:06:02

您应该查看图像视图(或任何 UIView 子类)的 contentMode 属性。将其设置为 UIViewContentModeScaleAspectFit,这将调整图像视图内容的大小以尽可能多地填充图像视图,而不会扭曲宽高比或剪切任何内容。在这种情况下,只需将图像视图设置为尽可能大,内容模式将处理其余的事情。

You should look at the contentMode property of your image view (or any UIView subclass, for that matter). Set it to UIViewContentModeScaleAspectFit, which will size the content of the image view to fill as much of it as possible without distorting the aspect ratio or clipping anything. In this case, just set the image view to be as large as possible, and the content mode will handle the rest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文