ios - How to resize view height based on it's subview avalability dynamically with Autolayout? -


i have situation window has 2 subviews , b , view contains 2 more subviews a1 , a2. have show view a's height based on if a1 , a2 available or not. example: if a1 available a2 not expected a's height a1 height + padding. , view b's height re-adjust based on vertical spacing constraints between view , b. - if a1 , a2 both available a'height = a1 height + padding+ a2 height + padding. , same b's height re-adjust based on vertical spacing constraints.

___________________________ | _________________________ | | _____________________  | |  |_a1__________________ | |  ______________________ | | |__a2__________________ | |________________________ | |  ________________________ | |  b | |  | |________________________ | | |__________________________   ___________________________ | _________________________ | | _____________________  | |  |_a1__________________ | |________________________ | |  ________________________ | |  b | |  | |________________________ | | |__________________________ 

i suppose have custom view called liveview contains of views describe. put code below, , explain later.

@implementation liveview    - (id)init {      self = [super init];      if (!self) return nil;            // iniitlize view hierarchy            return self;  }    + (bool)requiresconstraintbasedlayout  {      return yes;  }    // apple's recommended place adding/updating constraints  - (void)updateconstraints {      // define or update constraints        // tell constraints need updating      [self setneedsupdateconstraints];            // update constraints can animate change      [self updateconstraintsifneeded];            [uiview animatewithduration:0.4 animations:^{          [self layoutifneeded];      }];  }

as see, should initialize view hierarchy in - (id)init. , override + (bool)requiresconstraintbasedlayoutmethod , return yes. , override - (void)updateconstraints method should define or update constraint. when call methods in method - (void)updateconstraints update constraints , layout.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -