简体   繁体   English

Xcode-滚动视图-自动布局

[英]Xcode - Scroll View - Auto Layout

I'm using Xcode 8.3.2 and Swift 3 我正在使用Xcode 8.3.2和Swift 3

Created a story board with a scroll view that has zero margins to the superview 创建具有滚动视图的故事板,该视图具有到超级视图的零边距

The scroll view has margins as follows: 滚动视图的边距如下:

Top, trailing, bottom and leading space to superview as 0

The scroll view has one child, a container view with the following margins: 滚动视图有一个子视图,一个容器视图,具有以下边距:

Trailing, leading, bottom and top to superview at 0
Align center Y and align Center X in Superview
Intrinsic size to placeholder with height unchecked

XCode recommended putting in the align Center X and Y XCode建议将Align Center X和Y放入

Inside the container view, I would like to have two UI View. 在容器视图内,我想拥有两个UI视图。 The blue UI view I would like to always have a height of 236. The red view I would like to have a min height of say 400 and grow higher if more space is available 蓝色的UI视图我总是希望高度为236。红色的UI视图我希望最小高度为400,如果有更多可用空间,则高度会更高

Constraints for blue view are: 蓝色视图的约束是:

Height = 227
Trailing, leading, bottom to superview at 0
Top to red view as 0

Constraints for the red view are: 红色视图的约束为:

Height >= 400
Trailing, leading, top to superview at 0
Bottom to blue view as 0

When I flip the phone, the red view shrinks down and blue one stays at 227. 当我翻转手机时,红色视图缩小,蓝色视图停留在227。

The scroll view does not seem to be recognize the container is larger than the screen size. 滚动视图似乎无法识别出容器大于屏幕尺寸。

What can be causing the scroll view to not recognize that the container view is larger than the screen? 是什么导致滚动视图无法识别容器视图大于屏幕?

故事板

Emulator with screen rotated in landscape mode; 屏幕在横向模式下旋转的模拟器; red view is way too small even with height as >= 400. There is no scroll 即使高度> = 400,红色视图也太小。没有滚动

在此处输入图片说明

OBSERVATIONS: 观察:

It seems to be working as it should. 它似乎按预期方式工作。 In landscape mode, you have lesser screen height. 在横向模式下,屏幕高度较小。 According to your constraints, you want your first view's height to be 227 and the second view's height to be at least 400. This means that the minimum height possible adds up to 627. iPhone 5, in landscape mode, does not have that much height. 根据您的约束,您希望第一视图的高度为227,第二视图的高度至少为400。这意味着最小高度总计为627。iPhone 5在横向模式下没有那么高。 So iOS breaks some constraints to layout the screen as best it can (you might see that log in the console as well). 因此,iOS打破了一些限制,无法最好地布局屏幕(您可能还会在控制台中看到该日志)。

RECOMMENDATION: 建议:

Change the contentSize of the scrollView accordingly in order to accomodate the fulfilment of constraints. 相应地更改scrollViewcontentSize以便适应约束的实现。

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

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