objective c - iOS autolayout vs ScrollView : Contentsize issue -
what need
i have scrollview following hierarchy :
scrollview
. ^ contentview(uiview)
. - ^ view1(yellow)
. - ^ view2(gray)
view1
(yellow) has fixed height , pinned top of contentview. have specified constraints except height view2
. coz adding subview view2
(gray) programmatically , of random height.
the problem @ loss on how set height constraint of view2
. scrollview needs have constraints running top through bottom in order calculate contentsize
. height of view2
fixed after subview added, have necessary constraints determining height, of course.
what tried
1) first plan add subview , set constraints programmatically make scrollview happy. :
detailsview = [profiledetailsview instantiatefromnib]; [self.detailholder addsubview:detailsview]; [self.detailholder addconstraint:[nslayoutconstraint constraintwithitem:detailsview attribute:nslayoutattributetop relatedby:nslayoutrelationequal toitem:self.detailholder attribute:nslayoutattributetop multiplier:1.0 constant:0.0]]; [self.detailholder addconstraint:[nslayoutconstraint constraintwithitem:detailsview attribute:nslayoutattributeleading relatedby:nslayoutrelationequal toitem:self.detailholder attribute:nslayoutattributeleading multiplier:1.0 constant:0.0]]; [self.detailholder addconstraint:[nslayoutconstraint constraintwithitem:detailsview attribute:nslayoutattributebottom relatedby:nslayoutrelationequal toitem:self.detailholder attribute:nslayoutattributebottom multiplier:1.0 constant:0.0]]; [self.detailholder addconstraint:[nslayoutconstraint constraintwithitem:detailsview attribute:nslayoutattributetrailing relatedby:nslayoutrelationequal toitem:self.detailholder attribute:nslayoutattributetrailing multiplier:1.0 constant:0.0]];
the problem xcode gives me error scrollview has ambiguous scrollable content height
. cannot give fixed height view2
because subview later adding have necessary constraints set scrollview
's `contentsize.
2) tried adding height constraint view2
lower priority when subviews constraints kick in, height constraint overriden. doesn't seem work reason.
Comments
Post a Comment