Swift-为什么ScrollView不能全屏显示? [英] Swift - Why ScrollView not full screen?

查看:257
本文介绍了Swift-为什么ScrollView不能全屏显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIViewController中插入了ScrollView并拖动ScrollView来填充导航栏和下面的RAM标签之间的空间:

I had inserted a ScrollView into UIViewController and dragged ScrollView to fill the space between the navigation bar and the RAM label below:

但是当我运行该应用程序时,ScrollView不会填充空格:

But when I run the app, the ScrollView does not fill the space:

请帮助我!非常感谢.

P/S:对不起,我的英语不好.

P/S: Sorry for my english is bad.

推荐答案

滚动视图无法涵盖全部内容,因为您是在更大的手机上运行该应用程序的.最简单的解决方案是在iPhone 5上运行该应用程序.

The scroll view is not covering up the whole thing because you are running the app on a much bigger phone. The simplest solution is to run the app on iPhone 5.

但是,如果要在所有大小的iOS设备上解决此问题,都需要添加约束.

However, if you want to solve the problem on all sizes of iOS device, you need to add constraints.

约束是告诉视图何时应调整大小,调整大小以及将其放置在何处的东西.

Constraints are things that tells a view when and how much it should resize and where it should be positioned.

要添加约束,只需选择要向其添加约束的视图,然后转到右下角.您将看到4个按钮:

To add a constraint, just select the view you wish to add a constraint to and go to the bottom right corner. You will see 4 buttons:

  • 最左边的按钮用于将视图嵌入堆栈视图中.这是iOS 9的功能.如果您的部署目标较低,请忽略它.
  • 左侧的第二个按钮用于添加与对齐有关的约束-视图的边缘在哪里,基线是什么以及它在X和Y轴上的位置:

  • 左侧的第三个按钮用于添加与边距,宽度,高度以及在要求调整大小(例如,保持宽高比)时宽度和高度应如何变化有关的约束:

  • 最右边的按钮用于让Xcode决定应添加哪些约束.而且我认为大多数时候它的选择都是可以的.不过有时候,您仍然需要进行一些调整才能使它生效.

那么...我应该添加什么约束?"你问.

"So... what constraints should I add?" you asked.

好吧,我想我应该教你如何在想添加约束时思考.这样,您将来就可以自己解决问题.

Well, I think I should teach you how to think when you want to add a constraint. This way, you can figure it out yourself in the future.

首先应该让Xcode猜测您想要什么约束.只需单击最右边的按钮,然后单击重置为建议的约束".如果Xcode可以正确处理,则可以节省很多工作.因此,请记住始终先执行此操作.

You should first let Xcode guess what constraints you want. Just click the rightmost button and click "Reset to Suggested Constraints". This can save a lot of work if Xcode can get it right. So remember to always do this first.

然后,在各种设备上运行您的应用程序,并查看视图的位置,大小和对齐方式是否符合您的预期.如果不是,则可能必须添加和/或删除一些约束.

Then, run your app on various devices and see if the view's position, size, and alignment are as you expected. If it is not, you might have to add and/or remove some constraints.

例如,如果您发现不同设备上的视图大小始终相同(这可能很糟糕,因为这意味着某些内容在较小的设备上无法显示),可能是因为Xcode添加了宽度和/或视图的高度限制.您应该删除它,以免视图的宽度和/或高度不固定.

For example, if you found that your view is always the same size on different devices, (that could be bad because it means that some content my go out of view on smaller devices) it's probably because Xcode added a width and/or height constraint to the view. You should delete that so that the view's width and/or height is not fixed.

您可以在视图层次结构中找到视图的约束:

You can find your view's constraints in the view hierarchy:

只需选择约束,然后按Delete键即可.

Just select the constraint and press delete.

这篇关于Swift-为什么ScrollView不能全屏显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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