Core Animation: set anchorPoint on 10.8 to rotate a layer about its center
I don't see any methods on NSView
that are a direct “cover” for anchorPoint
.
What I do see in the 10.8 release notes, besides what you quoted, is this:
The anchorPoint is also always set to be (0,0), …
The anchorPoint
controls which point of the layer is at position
in the superlayer's coordinate system. NSView
sets self.layer.anchorPoint
to (0,0), which means the layer's lower-left corner is at self.layer.position
.
When you set anchorPoint
to (0.5,0.5), that means the center of the layer should be at the layer's position
. Since you didn't modify position
, this has the effect of moving the layer down and to the left, as you are seeing.
You need to compute the position
you want the layer to have when its anchorPoint
is (0.5,0.5), like this:
CGRect frame = _refreshButton.layer.frame;
CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
_refreshButton.layer.position = center;
_refreshButton.layer.anchorPoint = CGPointMake(0.5, 0.5);