ios - Combining NSLayoutConstraints with CALayer backed views does not animate correctly -


i have auto layout setup animation alters nslayoutcontraint constant value

// set slide in view's initial height 0 self.adviewheightconstraint = [nslayoutconstraint constraintwithitem:self.adcontainerview                                                            attribute:nslayoutattributeheight                                                            relatedby:nslayoutrelationequal                                                               toitem:nil                                                            attribute:nslayoutattributenotanattribute                                                           multiplier:1.0                                                             constant:0.0]; [self.view addconstraint:self.adviewheightconstraint];  //  later, set slid in view's height non-zero double delayinseconds = 3.0; dispatch_time_t poptime = dispatch_time(dispatch_time_now, (int64_t)(delayinseconds * nsec_per_sec)); dispatch_after(poptime, dispatch_get_main_queue(), ^(void){     self.adviewheightconstraint.constant = 100;     [uiview animatewithduration:2.5 animations:^{         [self.view layoutifneeded];     }]; }); 

this correctly animated sizes of views have , thus, works correctly. problem seeing, however, custom layer backed views have not being redrawn on duration of 2.5 sec animation.

the behavior seeing custom layer backed views asked draw final position @ beginning of animation, transform applied stretches view on duration of animation until looks correct.

enter image description here

what these 4 shots show red bar animating up, 2 blue views shrinking in height each accommodate size reduction. layer knows how draw correctly each bounds change, animation not asking redraw @ each step of animation... @ beginning. why black circle looks oval — same 2 halves image #4 stretched.

the custom calayer subclass has 1 overridden method: drawincontext:, , layer has needsdisplayonboundschange set yes.

thus, question remains... how can tell animation of nslayoutconstraints let views redraw during entire animation?

this known issue (if google you'll see couple of hits, though think answer, while admittedly focusing of different symptoms, articulate answer i've seen far describing problem uiview scaling during animation ... it's old answer, still applicable, believe).

the easiest solution, imho, put layer in view doesn't resize upon animation (e.g. new view, of fixed size, constraints keep centered on content view, doesn't change size content view does). way, can enjoy constraints-based animations, not lose custom layer's aspect ratio/size.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -