将动态高度设置为UIScrollView Swift [英] Setting Dynamic Height to UIScrollView Swift

查看:114
本文介绍了将动态高度设置为UIScrollView Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据我的 ScrollView

这是我得到的输出:

推荐答案

我们可以使用自动布局,在滚动视图中使用内容视图,该视图可以固定到滚动视图,并且高度和宽度约束与主视图相等看法.然后,如果我们希望高度动态变化,我们可以给高度限制设置一个比其他高度优先级低的优先级,因此内容视图的高度将由于其子视图而根据其固有大小增加.

We can use auto layout, where we use a content view in scrollview, which can be pinned to the scrollview and the height and width constraints given equal to the main view. Then if we want the height to vary dynamically we can give height constraint a low priority compared to the others and hence the content view's height will increase based on its intrinsic size, because of its sub views.

参考链接:

1) https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithScrollViews.html#//apple_ref/doc/uid/TP40010853-CH24-SW1

2) https://www.youtube.com/watch?v=6J22gHORk2I

这篇关于将动态高度设置为UIScrollView Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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