Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Having the exact same issue...</p> <p>Although I am unable to get the CALayer shadow on a view to animate nicely, at least the shadow does re-align properly after animation.</p> <p>My solution (which works fine in my application) is the set the shadowOpacity to 0, then reset it to the desired value AFTER the animation has completed. From a user's perspective, you cannot even tell the shadow is gone because the animations are typically too fast to perceive the difference.</p> <p>Here is an example of some code in my application, in which I am changing the constant value of a constraint, which is 'trailing edge to superview' NSLayoutContraint:</p> <pre><code>- (void) expandRightEdge { [self.mainNavRightEdge setConstant:newEdgeConstant]; [self updateCenterContainerShadow]; [UIView animateWithDuration:ANIMATION_DURATION delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [[NSNotificationCenter defaultCenter] postNotificationName:@"PanelLayoutChanged" object:nil]; [self.view layoutIfNeeded]; } completion:^(BOOL finished) { nil; }]; } - (void) updateCenterContainerShadow { self.centerContainer.layer.masksToBounds = NO; self.centerContainer.layer.shadowOpacity = 0.8f; self.centerContainer.layer.shadowRadius = 5.0f; self.centerContainer.layer.shadowOffset = CGSizeMake(0, 0); self.centerContainer.layer.shadowColor = [UIColor blackColor].CGColor; CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.centerContainer.layer.bounds].CGPath; [self.centerContainer.layer setShadowPath:shadowPath]; // Schedule a time to fade the shadow back in until we can figure out the CALayer + Auto-Layout issue [self performSelector:@selector(fadeInShadow) withObject:nil afterDelay:ANIMATION_DURATION+.05]; } - (void) fadeInShadow { [self.centerContainer.layer setShadowOpacity:0.8f]; } </code></pre> <p>Two things:</p> <ul> <li>I could have put the fadeInShadow in the completion block, but due to the way some of my other code is factored, this works better for me.</li> <li>I realize I am not performing a fade in with "fadeInShadow", but given how quickly it renderes after the completion of the animation, I found it is not necessary.</li> </ul> <p>Hope that helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload