【发布时间】:2019-03-03 02:02:06
【问题描述】:
我在 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 内部子视图的所有约束都与 SuperView (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 子类中更新滚动视图的高度吗?
谢谢
【问题讨论】:
标签: uiscrollview interface-builder swift4 xib