我在UIScrollView使用自动布局约束时遇到问题.
- ScrollView (leading, trailing, bottom and top spaces to superview)
-- ContainerView (leading, trailing, bottom and top spaces to superview)
--- ViewA (full width, top of superview)
--- ViewB (full width, below ViewA)
--- Button (full width, below ViewB)
ViewA和ViewB的初始高度为200点,但单击它可以将其垂直扩展到400点的高度.ViewA和ViewB通过更新其高度约束(从200到400)进行展开.以下是相应的代码片段:
if(self.contentVisible) {
heightConstraint.constant -= ContentHeight;
// + additional View's internal constraints update to hide additional content
self.contentVisible = NO;
} else {
heightConstraint.constant += ContentHeight;
// + additional View's internal constraints update to show additional content
self.contentVisible = YES;
}
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:.25f animations:^{
[self.view layoutIfNeeded];
}];
我的问题是,如果两个视图都展开,我需要能够滚动查看整个内容,而现在滚动不起作用.如何使用约束来更新滚动视图,以反映ViewA和ViewB高度的变化?
到目前为止,我能想到的唯一解决方案是在动画之后手动设置ContainerView的高度,即ViewA+ViewB+按钮的高度之和.但我相信有更好的解决方案吗?
谢谢