gpt4 book ai didi

objective-c - 核心动画 anchor 被忽略?

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:20 25 4
gpt4 key购买 nike

这段代码:(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"];

应该围绕其中心旋转我的图层。我已将 anchor 设置为 (0.5, 0.5),但 View 仍围绕其原点旋转。怎么会这样。我用谷歌搜索无济于事,所以我确定这可能是我所缺少的非常简单的东西......

NSLog 似乎报告了正确的值。第一个报告(0, 0),第二个报告(0.5, 0.5)

最佳答案

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

关于objective-c - 核心动画 anchor 被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/866661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com