[英]How to have a UIScrollView fit its content size, up until a max before scrolling in autolayout
I want to create a UIScrollView in autolayout that will fully contain it's content (does not scroll) until the content is a certain size (say 400), and then it starts scrolling. 我想在autolayout中创建一个UIScrollView,它将完全包含它的内容(不滚动),直到内容为特定大小(比如400),然后它开始滚动。
So I have my views laid out like this 所以我的意见就像这样
If I set Scroll View.height = ContentView.height
, then the scrollview expands to fit all of the content. 如果我设置Scroll View.height = ContentView.height
,则scrollview会展开以适合所有内容。 So far so good. 到现在为止还挺好。
Now if I try to set a max height via Scroll View.height <= 400
, what ends up happening is it sets the ContentView.height
as well (due to Scroll View.height = ContentView.height
) and the text becomes cut off and it doesn't scroll 现在,如果我尝试通过Scroll View.height <= 400
设置最大高度,最终发生的事情是设置ContentView.height
(由于Scroll View.height = ContentView.height
)并且文本被切断并且它不会滚动
So is this even possible to do with autolayout? 那么这甚至可能与自动布局有关吗? This seems easy to do with frames but I'd like a solution in autolayout. 这似乎很容易用帧,但我想在autolayout中的解决方案。
Here's the sample project if you'd like to play around yourself - https://github.com/iwllyu/content-hugging-uisv-with-max 如果您想自己玩一下,这是示例项目 - https://github.com/iwllyu/content-hugging-uisv-with-max
You have got everything else right. 你还有其他一切正确。 But for this to work you should set priority of Scroll View.height = ContentView.height
constraint less than the compression resistance priority of your subview (ie UILabel
here). 但为此,您应该将Scroll View.height = ContentView.height
约束的优先级设置为小于子视图的压缩阻力优先级(即UILabel
)。
So in your case anything below 750 will work. 因此,在您的情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.