views:

190

answers:

1

I want to animate the scaling down of a UIView, but not about its center: about a different point.

As a shot in the dark, I tried translating the view, scaling, then translating back, using a series of CGAffineTransforms. But it doesn't work: it still scales about the center.

Anyone know how to do this?

Thanks very much.

+2  A: 

Add the Quartz framework to your project and import the Quartz header

#import <QuartzCore/QuartzCore.h>

You can then set the anchor point of your view (around which animations are based) e.g.

myView.layer.anchorPoint = CGPointMake(0,0);

Note that the points are values between 0 and 1, with 0,0 being top left on the iPhone

Run Loop
Please consider marking my response as answered if it was helpful.
Run Loop
Thanks very much; this does indeed work. One follow-up problem, though: what I didn't say is that I'm using the scaling for a "bounce" effect. The view in question shrinks a bit, then expands back to its normal size. Using the "anchorPoint" approach shrinks the view appropriately, but when I grow the view again (using the identity matrix for the transform), the entire view has moved (translated) a bit. Is there a way I can get that view to be restored to its original location in a repeatable, anchorPoint-independent fashion? Thanks!
Greg Maletic
What might be easier is simply setting your view's frame's origins and sizes to reflect your end and start point and including it in an animation. I've found this an easier approach.
Run Loop