views:

216

answers:

1

I find this pretty confusing. When you want to rotate a view, it's going to be rotated by it's center point. But that's not always good. So if you need to rotate by an specified origin in your view, you would have to set the anchorPoint property of the view's layer.

Now, the problem is, that this anchorPoint property takes pretty confusing values for the average-intelligent programmer ;)

They're from 0 to 1, as far as I know. Also, the coordinate system is flipped to the view's coordinate system, where I think that 0 is the smallest value in the view's coordinate system, and 1 the largest.

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

would set the anchorPoint in the middle of the view.

What can I do, if I only know: - my view is 100 x 150 units big - I want the anchorPoint to be at x=100 and y=20, in my view coordinate system

Any idea how to achieve that?

+2  A: 

Sounds like you would use

myView.layer.anchorPoint = CGPointMake(1.0, 0.133);

They are just percentage values, no? 100/100 = 1 and 150/20 = 0.133.

Marc W
Yes, I thought that was what I told him here: http://stackoverflow.com/questions/857158/why-does-setting-the-anchorpoint-of-the-layers-bounds-rectangle-behave-so-strang . Like the color components in a CGColor, the X and Y coordinates of an anchorPoint are normalized to 1.0. All you have to do is divide by the size of the layer in that dimension.
Brad Larson