【发布时间】:2009-05-15 01:31:27
【问题描述】:
这段代码:(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)
【问题讨论】:
-
没有答案。只是想知道您是否将 self.layer 的锚点设置在其他地方。根据 (docs)[developer.apple.com/documentation/GraphicsImaging/Reference/… 它应该是 (0.5, 0.5)...
-
当你说它围绕它的原点旋转时,你是指左下角吗?
标签: objective-c cocoa macos core-animation