这段代码:( self是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"];
应该围绕它的中心旋转我的图层.我已经将锚点设置为(0.5,0.5),但视图仍然围绕其原点旋转.怎么会发生这种情况.我用google搜索无济于事,所以我确信它可能非常简单,我只是想念……
NSLog似乎报告了正确的价值观.第一个报告(0,0),第二个报告(0.5,0.5)
最佳答案 默认的anchorPoint默认为0.5,0.5,因此不必设置它.
您可能已经定位了图层的内容
看起来好像原点确实处于锚点.