Question

In one of my views that can be dragged, if the user drops it at an inappropriate place, it simply drops back to the original frame that was recorded when the mouse went down. This has been working fine for a few days with no animation, but I've decided to introduce animation:

-(void)dropToFrameOrigin:(NSPoint)newFrameOrigin animated:(BOOL)animated {
    if (animated) {
        NSRect newFrameRect = [self frame];
        newFrameRect.origin = newFrameOrigin;

        NSDictionary *animationInfo = [NSDictionary dictionaryWithObjectsAndKeys:self, NSViewAnimationTargetKey,
                                       [NSValue valueWithRect:[self frame]], NSViewAnimationStartFrameKey,
                                       [NSValue valueWithRect:newFrameRect], NSViewAnimationEndFrameKey,
                                        nil];
        NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:animationInfo]];
        [animation setDuration:0.2];
        [animation setAnimationCurve:NSAnimationLinear];
        [animation startAnimation];
        [animation release];
    } else {
        [self setFrameOrigin:newFrameOrigin];
    }
}

This is working with NSAnimationLinear, and the default NSAnimationEaseInOut, but what I actually want is merely the sense of deceleration, which I assume NSAnimationEaseOut is supposed to do. For some reason, when I use that however, the view snaps immediately to the frame it should end at, then animates sliding back to where the cursor dropped it (the start frame), then snaps back to (what should be) the end frame.

All the other modes (NSAnimationLinear, NSAnimationEaseIn, NSAnimationEaseInOut) seem to work just fine. Am I misunderstanding the purpose of NSAnimationEaseOut?

Was it helpful?

Solution

For some reason you have to flip the start and end frames to get NSAnimationEastOut to work. Plus, you need to set an animation delegate so you can be notified when the animation ends, where you must then manually set the view's frame to the original end frame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top