Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Animate scrollpoint?

Tags:

scroll

cocoa

- (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.

like image 732
Ganesh Nayak Avatar asked Jul 11 '09 09:07

Ganesh Nayak


People also ask

How do you animate an effect?

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.


2 Answers

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];
like image 55
Abhi Beckert Avatar answered Sep 20 '22 19:09

Abhi Beckert


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];
like image 44
Les Nie Avatar answered Sep 19 '22 19:09

Les Nie