UIStackView within UIScrollView is cut off

2019-08-23 11:31发布

I'm trying to use a UIStackView within a UIScrollView and I was hoping someone could point me in the right direction in creating the right constraints because I can't figure out what the problem is.

These are my constraints and ViewController structure. XCode

So DestCont is a UIView that has a fixed height and ContentCont should take up the rest of the space, which could be (and is) larger than the screen so it should be able to scroll.

When I test it out in the simulator, I have the following problem. (Resized it so it would fit in the 2MB cap)

Simulator

The green is the Root View and the black color is the ScrollView, as you can see, it cuts off the bottom portion of the ContentCont view.

EDIT

I changed the constraints, removed the fixed UIStackView height, but now, it doesn't show the bottom UIView that's in the UIStackView: EDIT

2条回答
孤傲高冷的网名
2楼-- · 2019-08-23 11:39

I ended up with being fine that just my "ContentCont" UIContainerView will scroll and fixed the switching by using the following tutorial: https://spin.atomicobject.com/2015/09/02/switch-container-views/.

查看更多
何必那么认真
3楼-- · 2019-08-23 11:58

From your screenshot we know that you have set the StackView's height constraint equals to the self.view's height. Then the height is fixed(equal to one screen's height), even though its content view's height may be larger than the screen.

And UIScrollView will calculate its contentSize depending on its content, so in your case its contentSize's height will always be one screen heigt.

Delete this height constraint, let the ContentCont's content decide the height of it. Also please make sure your constrains in your ContentCont are correct.

查看更多
登录 后发表回答