views:

565

answers:

1

This code: (self is a subclass of NSView)

    rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

 rotate.duration = 5;

 rotate.toValue = [NSNumber numberWithFloat:(2*pi)];

 rotate.repeatCount = INFINITY;

 rotate.removedOnCompletion = NO;
 rotate.fillMode = kCAFillModeForwards;

 NSLog(NSStringFromPoint(CGToNSPoint([self layer].anchorPoint)));

 [self layer].anchorPoint = CGPointMake(0.5, 0.5);

 NSLog(NSStringFromPoint(CGToNSPoint([self layer].anchorPoint)));

 [[self layer] addAnimation:rotate forKey:@"constantRotation"];

SHOULD rotate my layer around its center. I've set the anchor point to (0.5, 0.5), but the view still spins around its origin. How come this is happening. I've googled to no avail, so I'm sure it's probably something really simple that I'm just missing...

The NSLog's are seeming to report right values. The first one reports (0, 0) and the second one (0.5, 0.5)

+2  A: 

The default anchorPoint is by default 0.5, 0.5, so it should not have to be set. It is possible that you have positioned the content of the layer so that it appears as though the origin is really at the anchor point.

drudru