ScrollView contentView大小不会相应更改

时间:2019-05-28 14:35:07

标签: ios swift uiscrollview constraints

我有一个unsigned char,在其中更改了其ScrollView(具体高度)。当我这样做时,附加到contentSize上的ContentView的大小不会相应地更改。

ScrollView的{​​{1}}和ContentView等于height,而width为250(高度)。

请参阅我的约束条件:

Storjboard Constraints

出于测试目的,我将contentSize的高度更改为此:

ScrollView

预先感谢

1 个答案:

答案 0 :(得分:0)

您不能直接设置contentSize.height。请参阅this非常相似的问题。

基本上想要

scrollView.contentSize = CGSize(width: scrollView.contentSize.width, height: scrollView.contentSize.height + self.postedImageView.getImageHeight(forImage: selectedImage))

编辑:来自您的评论

你为什么不这样:

scrollView.ContentView.frame = CGRect(x: scrollView.ContentView.frame.origin.x, y: scrollView.ContentView.frame.origin.y, width: scrollView.ContentView.frame.width, height: scrollView.ContentView.frame.height + self.postedImageView.getImageHeight(forImage: selectedImage))

在调整内容大小的同时?

或者这个:

scrollView.ContentView.frame = CGRect(x: scrollView.ContentView.frame.origin.x, y: scrollView.ContentView.frame.origin.y, width: scrollView.ContentView.frame.width, height: scrollView.contentSize.height)
相关问题