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.

you can give view2 placeholder size removed @ runtime automatically make auto layout system happy

enter image description here


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -