【问题标题】:Core animation anchor point being ignored?核心动画锚点被忽略?
【发布时间】: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)

【问题讨论】:

标签: objective-c cocoa macos core-animation


【解决方案1】:

默认的anchorPoint默认是0.5,0.5,所以不应该设置。 您可能已经定位了图层的内容,以便 看起来好像原点真的在锚点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多