ios - Best way to redraw a custom view when orientation changes -


i have custom view:

-(id)initwithframe:(cgrect)frame {     cgrect framerect = cgrectmake(0, navigation_bar_height , frame.size.width, 4 * row_height + navigation_bar_height + message_body_padding);     self = [super initwithframe:framerect];     if (self) {         _selectionviewwidth = &frame.size.width;          [self initview];     }     return self; }  -(void)initview {     cgrect sectionsize = cgrectmake(0, 0 , *(_selectionviewwidth), row_height * 4);     _selectionview = [[uiview alloc] initwithframe:sectionsize];     [_selectionview setbackgroundcolor:[uicolor clearcolor]]; 

that use in view controller next way:

_mailattributesview = [[mailattributesview alloc]initwithframe:self.view.frame];     _mailattributesview.delegate = self;     [self.view addsubview:_mailattributesview]; 

so when orientation changes p l have next problem:

enter image description here

what's best way orientation change callback , redraw custom view?

you need override uiview layoutsubviews method , proceed manually layout subviews (looks to/from/cc/subject controls) there.

or, better configure subview spring/struts (or autolayout constraints) automatic layout. in code or via nib or storyboard.

edit: additional info since seem not getting layoutsubviews on orientation change.

my guess viewcontroller-view isn't resizing/repositioning mailattributes view either.

it's not clear when/where add mailattributesview veiwcontroller view. if you're doing in viewdidload viewcontroller view may or may not have valid frame size (depending if loaded nib or not). it's best not depend on viewcontroller-view frame layout purposes in viewdidload.

rather, layout viewcontroller-view subviews in viewwilllayoutsubviews. there viewcontroller-view frame set.

others may point out can set autoresizingflags in viewdidload subviews, there gotcha's this. if parent view has 0 size, , subviews inset have springs/struts defined glue them parent view edges.

the best solution overall imo setup autolayout constraints contained in viewcontroller view, on down.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -