使 UIScrollView 适合内容

Fit UIScrollView to the content

滚动视图中 space 下面的内容太多了。

请参考下面的截图。如何使滚动视图适合内容。问题似乎是底部space。如果我只是按照自动布局保留它,它会在内容下面得到太多 space。

如果我将它设置为 8,它可以工作,但情节提要会抱怨限制,请参见第 10 号屏幕截图。 2 下面。如果这个问题可以解决,那么我会有解决方案。

我在其他帖子中看到了一些建议(例如 How do I auto size a UIScrollView to fit the content),但它们并没有解决问题。如何解决?

需要的约束:

  • ScrollView : top , leading , trailing , bottom

  • contentView : top , leading , trailing , bottom => to superView && equal width to main outer view

  • textView : top , leading , trailing , bottom => to contentView , height ( such as 50 )

顺便说一句,您不需要所有这些,因为 UITextView 继承自 UIScrollview,因此默认情况下它是可滚动的。
如果您需要根据书面文字调整大小,请使用:

self.textView.frame.size = self.textView.contentSize