- (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)];
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我需要为滚动设置动画.我怎样才能做到这一点?谢谢.
Abh*_*ert 12
您可以创建一个子类NSAnimation来执行此操作.我已经创建了一个作为我的开源项目的一部分(使用公共域许可证).
你可以在这里找到它:https://github.com/abhibeckert/Dux/blob/master/Dux/DuxScrollViewAnimation.m(注意:这个项目启用了ARC.如果你不使用ARC,你需要在适当时更新).
例:
[DuxScrollViewAnimation animatedScrollToPoint:NSMakePoint(x,y) inScrollView:self.enclosingScrollView];
Run Code Online (Sandbox Code Playgroud)
在我的应用程序,我设置clipView的boundsOrigin使用其动画师:
[NSAnimationContext beginGrouping];
NSClipView* clipView = [[myView enclosingScrollView] contentView];
NSPoint newOrigin = [clipView bounds].origin;
newOrigin.x = my_new_origin.x;
[[clipView animator] setBoundsOrigin:newOrigin];
[NSAnimationContext endGrouping];
Run Code Online (Sandbox Code Playgroud)