UIStackView within UIScrollView is cut off

雨燕双飞 提交于 2019-12-11 12:09:48

问题


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.

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)

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:


回答1:


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.




回答2:


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/.



来源:https://stackoverflow.com/questions/48863166/uistackview-within-uiscrollview-is-cut-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!