简体   繁体   中英

Xcode - Scroll View - Auto Layout

I'm using Xcode 8.3.2 and 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

Inside the container view, I would like to have two UI View. 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

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.

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

在此处输入图片说明

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. So iOS breaks some constraints to layout the screen as best it can (you might see that log in the console as well).

RECOMMENDATION:

Change the contentSize of the scrollView accordingly in order to accomodate the fulfilment of constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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