title: Smooth animation when animating a CALayer's shadowPath
body: <p>In my app I have a <code>UIView</code> that is using <code>CALayer</code> in order to achieve a shadow:</p>
  
  <pre><code>@implementation MyUIView
  
      - (instancetype) initWithFrame:(CGRect)frame {
          self = [super initWithFrame:frame];
          if(!self) return self;
  
          self.layer.shadowColor = [UIColor colorWithWhite:0 alpha:.2].CGColor;
          self.layer.shadowOffset = CGSizeMake(0, 2);
          self.layer.shadowOpacity = 1;
          self.layer.shadowRadius = 1;
  
          return self;
      }
  
  @end
  </code></pre>
  
  <p>If I want anything approaching reasonable performance, I have to define the <code>CALayer</code>'s <code>shadowPath</code>:</p>
  
  <pre><code>@implementation MyUIView
  
      - (void) setFrame:(CGRect)frame {
          [super setFrame:frame];
  
          self.layer.shadowPath = CGPathCreateWithRect(self.bounds, NULL);
      }
  
  @end
  </code></pre>
  
  <p>I've noticed two things whenever I animate this <code>UIView</code>:</p>
  
  <ol>
  <li><p>If I <strong>don't</strong> use a <code>shadowPath</code>, the shadow animates along nicely with rotations and frame size changes. The caveat here being very slow animation and a general lack of performance.</p></li>
  <li><p>If I <strong>do</strong> use a <code>shadowPath</code> whenever the <code>UIView</code> is animated the animation is smooth and timely, however the shadow's transition itself is much more block-like (and less smooth) than it is without a <code>shadowPath</code>.</p></li>
  </ol>
  
  <p><strong>Examples:</strong></p>
  
  <ul>
  <li><strong>With</strong> <code>shadowPath</code>: <a href="https://gfycat.com/ColdBlissfulIndusriverdolphin" rel="nofollow">https://gfycat.com/ColdBlissfulIndusriverdolphin</a> (notice how the shadow behaves like a poorly transformed rectangle?)</li>
  <li><strong>Without</strong> <code>shadowPath</code> (the slowness of the animation is more apparent on the device, but you get the idea):  <a href="https://gfycat.com/ActiveRemorsefulBandicoot" rel="nofollow">https://gfycat.com/ActiveRemorsefulBandicoot</a></li>
  </ul>
  
  <p><strong>Edit:</strong></p>
  
  <p>It's worth noting that these animations are implicit - I'm not invoking them myself. They are the result of the <code>UIViewController</code> rotating with the device orientation. The shadow is on a <code>UIView</code> that changes size during rotation.</p>