Setting constraints to UIScrollView

柔情痞子 提交于 2019-12-25 02:32:13

问题


Need some help to set constraints to UIScrollView.

I tried to follow the instructions here: https://developer.apple.com/library/ios/technotes/tn2154/_index.html (Mixed approach).

Setting 4 sided constraints to UIScrollView. Then set 4 sided constraints to the buttonContainer.

This the result:

However xcode is giving this error message:

If I try xcode's recommendation, either the scrollview will not scroll, or it doesn't display at all.

Any idea what's wrong here?


回答1:


The messages you are getting tell you what to do. The scroll view sets its content size and becomes scrollable through the constraints pinning its subview(s) to the scroll view itself. Those constraints must therefore provide sufficient information. You have not provided enough internal constraints to describe the height and width of the scrollable area (the content size).

In other words, think of the constraints as sizing the buttonContainer from the inside out. That is what you have neglected to do. You can solve this, for instance, simply by giving the buttonContainer an absolute width constraint and an absolute height constraint. And those values need to be bigger than the size of the scroll view itself if the content is to be scrollable.



来源:https://stackoverflow.com/questions/21719089/setting-constraints-to-uiscrollview

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