使ScrollView与自动布局和情节提要一起使用 [英] Getting ScrollView to Work with Autolayout and Storyboard

查看:59
本文介绍了使ScrollView与自动布局和情节提要一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为要构建的应用程序制作一个非常简单的布局-但我似乎在使用ScrollView并通过Storyboard使其正常工作.基本上,我尝试在下面进行构建:

I am trying to make a really simple layout for an app I want to build - but I seem to be struggling with ScrollView and getting it to work via Storyboard. Basically I am trying to build below:

我已经使用一些教程完成了约束-但它要么无法滚动,要么看起来不正确.有什么建议吗?

I have done the constraints using several tutorials - but it either doesn't scroll or it looks wrong. Any suggestions?

我收到以下警告:

推荐答案

使用约束进行布局时,必须提供UIScrollView的contentSize.

You have to provide the contentSize for a UIScrollView when laying it out using constraints.

例如:

您可以将View的宽度设置为与scrollView相等,因为这将提供scrollview内容的宽度.然后,要提供内容高度,请垂直布置红色和黄色视图,并使用它们提供视图的高度.这意味着您必须为黄色视图提供初始高度,或者您可以使用提供了internalContentSize的视图来确定黄色视图的高度,因此不必手动更改它.

You can set the width of View to be equal to the scrollView as this will provide the width of the scrollview's content. Then, to provide content height, layout red and yellow views vertically and use them to provide the height of View. This means you'll have to provide initial height for yellow view, or you can use a view that provides an intrinsicContentSize to determine the yellow view height so you don't have to manually change it.

我还认为您必须删除redview顶部==布局指南顶部,并添加redview顶部==视图顶部和yellowview底部==视图底部

Also I think you have to remove redview top == layout guide top, and add redview top == View top and yellowview bottom == View bottom

这篇关于使ScrollView与自动布局和情节提要一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆