Sebastian
Sebastian

Reputation: 901

Scaling with Core Animation

I have a NSScrollView that I want to scale down 50%. I do this with the below code:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

animation.fromValue = [NSNumber numberWithFloat:1.00];
animation.toValue = [NSNumber numberWithFloat:0.50];
[animation setDuration:0.20f];

[animation setFillMode:kCAFillModeForwards];
[animation setRemovedOnCompletion:NO];

[self.scrollView.layer addAnimation:animation forKey:@"drag"];

This works, but the scroll view's document view receives mousedown events when I click outside of the scaled down view. So although the scroll view and its content visually looks scaled down, they technically aren't.

How would I go about doing this?

Thanks!

Upvotes: 4

Views: 3192

Answers (1)

Duncan C
Duncan C

Reputation: 131491

Layer animation acts exactly as you describe (The animations only change the appearance, not the underlying geometry.)

Try using UIView block animation and change the scroll view's transform rather than the layer's.

EDIT:

Oh. Sorry, I thought this was iOS. I guess I should have noticed that you said it was an NSView, not a UIView. I do most of my work in iOS these days, and my OSX experience is mostly from before the days of Core Animation.

I think the answer is to get the view's animation proxy and set the change on that, but I've only done a few learning exercises with animation proxies in Mac OS, so I'd have to do some digging to look up the specifics.

Upvotes: 2

Related Questions