title: Explicit animation of NSView using core animation
body: <p>I'm trying to slide in a <code>NSView</code> using core animation.  I think I need to use explicit animation rather than relying on something like <code>[[view animator] setFrame:newFrame]</code>.  This is mainly because I need to set the animation delegate in order to take action after the animation is finished.  </p>
  
  <p>I have it working just fine using the animator, but as I said, I need to be notified when the animation finishes.   My code currently looks like:</p>
  
  <pre><code>// Animate the controlView
  NSRect viewRect = [controlView frame];
  NSPoint startingPoint = viewRect.origin;
  NSPoint endingPoint = startingPoint;
  endingPoint.x += viewRect.size.width;
  [[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
  
  CABasicAnimation *controlPosAnim = [CABasicAnimation animationWithKeyPath:@"position"];
  [controlPosAnim setFromValue:[NSValue valueWithPoint:startingPoint]];
  [controlPosAnim setToValue:[NSValue valueWithPoint:endingPoint]];
  [controlPosAnim setDelegate:self];
  [[controlView layer] addAnimation:controlPosAnim forKey:@"controlViewPosition"];
  </code></pre>
  
  <p>This visually works (and I get notified at the end) but it looks like the actual controlView doesn't get moved.  If I cause the window to refresh, the controlView disappears.  I tried replacing</p>
  
  <pre><code>[[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
  </code></pre>
  
  <p>with</p>
  
  <pre><code>[controlView setFrame:newFrame];
  </code></pre>
  
  <p>and that does cause the view (and layer) to move, but it is corrupting something such that my app dies with a seg fault soon afterwards.</p>
  
  <p>Most of the examples of explicit animation seem to only be moving a <code>CALayer</code>.  There must be a way to moving the <code>NSView</code> and also being able to set a delegate.  Any help would be appreciated.</p>