ios - 将动态高度设置为 UIScrollView Swift

标签 ios uiscrollview swift2 height

如何根据我的 ScrollView 中的内容/ subview 设置 UIScrollView 的动态高度

这是我得到的输出:

enter image description here

最佳答案

我们可以使用自动布局,我们在 scrollview 中使用一个内容 View ,它可以固定到 scrollview 并且给定的高度和宽度约束等于主视图。然后,如果我们希望高度动态变化,我们可以为高度约束赋予一个比其他约束低的优先级,因此内容 View 的高度将根据其固有大小增加,因为它有 subview 。

引用链接:

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

关于ios - 将动态高度设置为 UIScrollView Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40944994/

相关文章:

objective-c - 仅在参数更改时处理实例方法中的代码

ios - 当单元格当前滑开时按下 UITableViewCell

ios - UIPanGestureRecognizer 与 UIPinchGestureRecognizer 的 super View 冲突

swift2 - 'init'是该类型的成员;使用'type(of: …)'初始化一个新对象

ios - NSCocoaErrorDomain 代码=3840

iOS - 在 Objective-c 和 Swift 上一起实现 UI

ios - 如何在 Swift 4 中使用 FetchedResultsController 获取 DateSectionTitles

ios - Swift:阻止滚动内的图像上下移动

iphone - UIScrollView 未使用 setContentOffset 滚动到正确位置 :animated:

ios - swift2.0,从 REST 调用返回信息(Alamofire)