将背景图像缩放到 iPhone 10 [英] Scale background image to iPhone 10

查看:32
本文介绍了将背景图像缩放到 iPhone 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Swift 4、XCode 9.我有一个 iOS 应用程序,它有一个使用故事板设置的背景图像.实际故事板文件是从 iPhone SE 的参考框架中查看的.但是,我从来没有遇到过将图像缩放到更大的手机尺寸的问题,除了现在的 iPhone 10.它不会填满整个屏幕.我怎样才能解决这个问题?背景通过图像视图显示.我尝试通过故事板和以编程方式更改图像视图的高度,但没有运气.同样,这只是 iPhone 10 上的问题.

I'm using Swift 4, XCode 9. I have an iOS application which has a background image which was set using storyboard. The actual storyboard file is viewed from the frame of reference of an iPhone SE. However, I've never had a problem with the image scaling to bigger phone sizes, except now for iPhone 10. It won't fill the whole screen. How can I fix this? The background is displayed through an image view. I've tried changing the height of the image view both via story board and programmatically with no luck. Again, this only is a problem on iPhone 10.

我通过添加特定的 iPhone X 启动图像在一定程度上解决了这个问题,但现在我的组件都向左移动

I've somewhat fixed this problem by adding a specific iPhone X Launch Image, but now my components are all shifted to the left

推荐答案

有几个步骤你应该小心.

There are few steps you should be careful.

步骤 1:在界面生成器中选择设备 iPhone X.

第 2 步:向 ViewController 添加完整图像.

第 3 步:通过选择底部菜单添加约束(应该全为零).

我们都准备好了.如果您从 iPhone X 或更新的设备开始添加,它会自动调整所有以前的设备的底部、顶部、左侧和右侧的约束.

We all set. If you start adding from iPhone X or later devices, it will automatically adjust the bottom, top, left and right constraints accordingly all the previous devices.

注意:当我们添加手动约束时,请注意 SafeAreaLayout 的优先级高于手动约束.

NB: While we adding manual constraints, be aware that the SafeAreaLayout has the first priority than the manual constraints.

另一种方法(你可以使用任何一种取决于你的兴趣)

Another method (You can use either one depends upon your interest)

为背景图像提供前导、试验、顶部和底部约束.然后选择底部约束,并从尺寸检查器中选择第一项作为Superview

Provide leading, trialing, top and bottom constraints to the background image. Then select the bottom constrain, and from the size inspector choose the first item as Superview

我相信这会对某人有所帮助.干杯.

I believe this will help somebody. Cheers.

这篇关于将背景图像缩放到 iPhone 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆