更新 UIScrollView 的高度



>我在 xib 文件中有以下设置

ScrollView (UIScrollView)
- ContentView (UIView)
- ImageSlider (FSPagerView)
- ClinicName (UILabel)
- ClinicSlogan (UILabel)
- LineSeparatorView (UIView)
- ClinicProfile (UITextView)
- SectionView (Custom UIView)
- Doctors View (UICollectionView) - Horizontal Scrolling

在 IB 中按以下方式设置约束

// ScrollView Constraints
ScrollView.Top = NavigationView.Bottom
ScrollView.Leading = SafeArea.Leading
SafeArea.Trailing = ScrollView.Trailing
SafeArea.Bottom = ScrollView.Bottom
// ContentView Constraints
ContentView.Top = SuperView.Top
ContentView.Leading = SuperView.Leading
SuperView.Trailing = ContentView.Trailing
SuperView.Bottom = ContentView.Bottom
ContentView.Height = SuperView.Height (Priority@250)
ContentView.Width = SuperView.Width

ContentView内部子视图的所有约束都与超级视图 (ContentView( 相关设置

viewDidLoad(),我正在更新ClinicSlogan和ClinicProfile的文本值,并更新高度常量。这有效,但是当我更新滚动视图的高度时它不起作用,这是我在下面调用的代码viewDidLoad()

self.clinicSloganLabelHeightConstraint.constant = estimatedFrameFor(
text: self.clinicSloganLabel.text!,
font: self.clinicSloganLabel.font!,
width: self.clinicSloganLabel.frame.width
).height
self.clinicProfileTextViewHeightConstraint.constant = self.clinicProfileTextView.sizeThatFits(
CGSize(width: self.clinicProfileTextView.frame.width, height: .infinity)
).height
self.scrollView.contentSize.height = 2000

我尝试将代码放在viewDidLayoutSubviews((中,问题是,我在ScrollView((中使用UICollectionView((,它停止滚动调用的时刻viewDidLayoutSubviews方法。

你能帮助更新UIViewController子类中滚动视图的高度的正确方向吗?

谢谢

好的,我在 IB 中使用自动布局解决了它,我所做的是,最后一个视图我在内容视图中添加了"底部空间到容器"约束,现在所有内容都在自动调整。

最新更新