ios - Shifting UIViews with Auto Layout when one ore more views are hidden -
i have view has header. header has 4 views show images on right. call them icons since every of them shows or draw glyph. depending on data, icon 2, 3 or 4 may hidden given me 6 possible combinations. when hidden, every invisible icon occupy space, giving 1 or more "holes" in visualization. i'm using right now.
[header addsubview:_label]; [header addsubview:_icon1]; [header addsubview:_icon2]; [header addsubview:_icon3]; [header addsubview:_icon4]; nsdictionary *headerviewdict = nsdictionaryofvariablebindings(_label, _icon1, _icon2, _icon3, _icon4); [header addconstraints:[nslayoutconstraint constraintswithvisualformat:@"|-2-[_label]-0-[_icon4(>=0,14)]-1-[_icon3(>=0,14)]-1-[_icon2(>=0,14)]-1-[_icon1(14)]-2-|" options:nil metrics:nil views:headerviewdict]]; [header addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[_label]|" options:nil metrics:nil views:headerviewdict]]; [header addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[_icon1]|" options:nil metrics:nil views:headerviewdict]]; [header addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[_icon2]|" options:nil metrics:nil views:headerviewdict]]; [header addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[_icon3]|" options:nil metrics:nil views:headerviewdict]]; [header addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[_icon4]|" options:nil metrics:nil views:headerviewdict]]; i've read (https://stackoverflow.com/a/18066138/1360888) solve there 2 possibilities over-constrain or change constant. i'm quite new autolayout , have used visual format language (since build view code only) did not understood how apply solution case.
how can create fluid layout view?
note: in app have lot of views header visible @ same time, performance important.
what create array of icons(as call them, uiimageviews?). update contents of array according data.
on viewwilllayoutsubviews
- check array [1, 2, 3, 4]
- remove constraints
- set new constraints according content array. important thing here check element of array nil. autolayout not process nil elements correctly , fails.
removing constraints:
//clear constraints (nslayoutconstraint *constraint in [self.view constraints]) { [self.view removeconstraint:constraint]; } adding constraints:
if (mycustomview) {//constraintswithvisualformat not support handling nil //add constraints mycustomview here } viewwilllayoutsubviews
/** * update constraints before laying subviews * */ - (void) viewwilllayoutsubviews { [super viewwilllayoutsubviews]; //remove constraints //set new constraints }
Comments
Post a Comment