开发者

Using NSViewAnimation with NSAnimationEaseOut weird behaviour

开发者 https://www.devze.com 2023-02-01 21:14 出处:网络
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

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消