ios - How do I get auto layout to reposition a view when it's sibling view changes size? -
i have view controller 2 views (greenview, redview) , switch:

i have constraint on redview top space of 50px greenview. here constraints on redview:

i have switch when tapped toggles height of greenview 50px 100px.
when launch app, views laid out want, when switch tapped, greenview frame changes height of 50 100, redview doesn't expect - shift it's y position 50px down maintain top space constraint assigned. have inequality constraint put on bottom space of redview there no conflicts, , calling [self.redview layoutifneeded].
here's relevant code:
- (ibaction)switchtapped { if (theswitch.ison) { greenview.frame = cgrectmake(0, 30, 320, 100); [redview layoutifneeded]; } else { greenview.frame = cgrectmake(0, 30, 320, 50); [redview layoutifneeded]; } why isn't redview's y position being updated?
i have watched wwdc videos, seem mention calling layoutifneeded in passing. missing?
here's looks when launched:

and here when switch tapped:

there couple things causing problems. first thing autolayout supposed ignore object's frame. if want change height of something, change height constraint, not frame height. because constraints applied after layout , override frame changes. in addition, red view looks constrained superview "view" not "greenview". far editing constraints, can set iboutlet , modify constant property of uilayoutconstraint object.
Comments
Post a Comment