I am trying to NSView
in an NSView
using the main animation. I think I need to use explicit animation, and not rely on something like [[view animator] setFrame:newFrame]
. This is mainly because I need to set an animation delegate to take action after the animation finishes.
It works fine for me, using the animator, but, as I said, I need to get a notification when the animation ends. Currently my code is as follows:
// 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"];
This works visually (and I get a notification at the end), but it looks like the actual control is not moving. If I make the window refresh, the View control will disappear. I tried to replace
[[controlView layer] setPosition:NSPointToCGPoint(endingPoint)];
from
[controlView setFrame:newFrame]
and this causes the view (and layer) to move, but it distorts something so that my application will soon fail with a seg error.
Most examples of explicit animations seem to move only CALayer
. There must be a way to move the NSView
, as well as the ability to set a delegate. Any help would be appreciated.
btschumy
source share