我遇到了使用自動佈局約束的UIScrollView的麻煩。 我有以下視圖層次結構,通過設置IB約束:自動佈局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 + Button高度的總和。但我相信有更好的解決方案?
由於
http://stackoverflow.com/questions/13499467/uiscrollview-doesnt-use-autolayout-constraints也非常有幫助 –