ios 在 iPhone X 屏幕底部获得一个空白区域(Xcode 9)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46322150/
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
Getting a white space at bottom of iPhone X screen (Xcode 9)
提问by Harish
I'm using Xcode 9 for my project and I'm getting a white space at the bottom, here is the screenshot:
我在我的项目中使用 Xcode 9,底部有一个空白,这是屏幕截图:
Also I'm using storyboard to design with 4 inches (iphone 5s/SE) as layout.
此外,我正在使用故事板设计 4 英寸(iphone 5s/SE)作为布局。
How to avoid the white space?
如何避免空白?
回答by Ketan Parmar
Your bottom constraints
should be from view
not from the bottom layout guide
or safe area
(xcode 9 specific) and your distance should be zero.
您bottom constraints
应该view
不是来自bottom layout guide
或safe area
(特定于xcode 9)并且您的距离应该为零。
Default it was pinned with layout guides
, so give it with view
!
默认它是固定的layout guides
,所以给它view
!
Refer below screenshot for better understanding,
请参阅下面的屏幕截图以更好地理解,
to open this dialogue, click drop down icon of field contains 0
!
要打开此对话框,请单击包含字段的下拉图标0
!
You can do same for top constraint
also!
你也可以这样做top constraint
!
Update :
更新 :
Second main important thing,
第二个重要的事情,
you should use storyboard for your launch or splashscreen. If you are using launch image then replace it by new launch image of xcode 9
and it have option for the image of iphone x.
您应该将故事板用于启动或启动画面。如果您使用的是启动图像,则将其替换为新的启动图像,xcode 9
并且它可以选择 iphone x 的图像。
Then you will not found white space any more!
那你就再也找不到空白了!
Refer below screenshot.
请参阅下面的屏幕截图。
回答by jonaszmclaren
This white space is your main view. If you want your image view to fill the whole area, pin it with 0 space to the superview, not to Bottom Layout Guide or Safe Area. To achieve this, select to view scene in storyboard as iPhone X and pin the image view as below:
这个空白区域是您的主要视图。如果你想让你的图像视图填满整个区域,用 0 空间将它固定到超级视图,而不是底部布局指南或安全区域。为此,请选择以 iPhone X 的形式查看情节提要中的场景并将图像视图固定如下:
It is also possible to pin the bottom of image view to superview when not in iPhone X mode: when you pin by dragging with Ctrl, when the list of constaints appears press Option key (alt) and you will see "Bottom Space to Container Margin".
当不在 iPhone X 模式下时,也可以将图像视图的底部固定到超级视图:当您通过 Ctrl 拖动固定时,当约束列表出现时,按 Option 键 (alt),您将看到“底部空间到容器边距”。
回答by regina_fallangi
Neither of the two answers above worked for me. Only setting
以上两个答案都不适合我。仅设置
scrollView.contentInsetAdjustmentBehavior = .never
I have a stackView inside my scrollView and the elements in the stackView have fixed sizes, so I have no need to inset adjustment and this works.
我的 scrollView 中有一个 stackView 并且 stackView 中的元素具有固定的大小,所以我不需要插入调整,这有效。
Credit goes to How to get rid of safeAreaInsets on UIScrollview (iOS 11, iPhoneX)
回答by Narasimha Nallamsetty
For me this worked:
对我来说这有效:
1) Select image for which you are setting up constraints
1) 选择要为其设置约束的图像
2) Go to Attribute inspector in the right panel
2)转到右侧面板中的属性检查器
3) Select Scale to Fill
as Content Mode
3)选择Scale to Fill
为Content Mode