此代码:( 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),但视图仍然围绕其原点旋转。怎么会发生这种情况。我用谷歌搜索无济于事,所以我确信这可能是一件非常简单的事情,我只是想念......
NSLog似乎报告了正确的价值观。第一个报告(0,0),第二个报告(0.5,0.5)
答案 0 :(得分:2)
默认的anchorPoint默认为0.5,0.5,因此不必设置它。 您可能已经定位了图层的内容 似乎原点确实处于锚点。