- (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)];
}
}
In the above code I need to animate the scrolling. How can I achieve this? Thanks.
Add animations to text, pictures, shapes, and more in your presentation. Select the object or text you want to animate. Select Animations and choose an animation. Select Effect Options and choose an effect.
You can create a subclass of NSAnimation
to do this. I've created one as part of an open source project of mine (with public domain license).
You can find it here: https://github.com/abhibeckert/Dux/blob/master/Dux/DuxScrollViewAnimation.m (note: this project has ARC enabled. If you're not using ARC you will need to update as appropriate).
Example:
[DuxScrollViewAnimation animatedScrollToPoint:NSMakePoint(x,y) inScrollView:self.enclosingScrollView];
In my app, I set the clipView
's boundsOrigin
using its animator:
[NSAnimationContext beginGrouping];
NSClipView* clipView = [[myView enclosingScrollView] contentView];
NSPoint newOrigin = [clipView bounds].origin;
newOrigin.x = my_new_origin.x;
[[clipView animator] setBoundsOrigin:newOrigin];
[NSAnimationContext endGrouping];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With