- (void)mouseDragged:(NSEvent *)theEvent {
    NSSize dynamicImageSize;
    dynamicImageSize = [[self image] size];
    NSSize contentSize = [(NSScrollView*)[[self superview] superview] contentSize];
    if(dynamicImageSize.height > contentSize.height || dynamicImageSize.width > contentSize.width)
    {
        float x = startOrigin.x - ([theEvent locationInWindow].x - startPt.x);
        float y = startOrigin.y - ([theEvent locationInWindow].y - startPt.y);
        [self scrollPoint:NSMakePoint(x, y)];
    }
}

在上面的代码中,我需要对滚动进行动画处理。我怎样才能做到这一点?
谢谢。

最佳答案

在我的应用程序中,我使用动画器设置clipViewboundsOrigin:

[NSAnimationContext beginGrouping];
NSClipView* clipView = [[myView enclosingScrollView] contentView];
NSPoint newOrigin = [clipView bounds].origin;
newOrigin.x = my_new_origin.x;
[[clipView animator] setBoundsOrigin:newOrigin];
[NSAnimationContext endGrouping];

关于cocoa - 如何对滚动点进行动画处理?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1113353/

10-09 13:18