ios - Why do I need to set constraint constant after some delay? -


i adding view programatically , changing constant of height constraint not set width screen width in viewdidload method. width set when put line in after 0.2 seconds delay queue.

below code

added in viewdidload

dispatch_after(dispatch_time(dispatch_time_now, (int64_t)(0.2 * nsec_per_sec)), dispatch_get_main_queue(), ^{ careaview = [[[nsbundle mainbundle] loadnibnamed:@"aview" owner:nil options:nil] objectatindex:0]; [_vwcomplaintarea addsubview:careaview]; [self setconstraintlayout:careaview tovw:_vwcomplaintarea]; [_firstviewheightconstraint setconstant:_firstviewheightconstraint.constant + careaview.bounds.size.height]; [_heightforcomplaintare setconstant:careaview.bounds.size.height]; });

-(void)setconstraintlayout:(uiview *)vw tovw:(uiview *)tovw { [vw autosetdimensionstosize:cgsizemake(tovw.bounds.size.width, vw.bounds.size.height)]; [vw autopinedge:aledgetop toedge:aledgetop ofview:tovw]; [vw autopinedge:aledgeleft toedge:aledgeleft ofview:tovw]; }

can suggest best way set constraints programatically in viewdidload.

thanks.

you can change constraint constant @ time wish. understood, trying set constant equal view width value, taken view's frame or bounds property. need know, in viewdidload properties don't have actual values since use autolayout; actual values in viewdidlayoutsubviews method (note can called multiple times). when add delay 0.2 sec, autolayout processes finished, thats why right result. so, can assign constraint constant in viewdidlayoutsubviews, or better add new constraint equal width's:

let someproportion: cgfloat = 2 view.addconstraint(nslayoutconstraint(item: yourview, attribute: .width, relatedby: .equal, toitem: view, attribute: .width, multiplier: someproportion, constant: 0)) 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -