gpt4 book ai didi

iphone - CAKeyframeAnimation 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:17 25 4
gpt4 key购买 nike

我正在尝试使用以下代码制作一个简单的 CAKeyframeAnimation:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

CALayer *rotLayer = [CALayer layer];
rotLayer.bounds = CGRectMake(0.0, 0.0, 100.0, 50.0);
rotLayer.anchorPoint = CGPointMake(0.5, 0.5);
rotLayer.position = CGPointMake(160.0, 200.0);
rotLayer.backgroundColor = [UIColor redColor].CGColor;

[self.view.layer addSublayer:rotLayer];

/*
CABasicAnimation *basic = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
basic.duration = 3.0;
basic.fromValue = [NSNumber numberWithFloat:0.0];
basic.toValue = [NSNumber numberWithFloat:2.0];

[rotLayer addAnimation:basic forKey:@"basic"];
*/

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 3.0;
animation.keyTimes = @[ [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:1.0] ];
animation.values = @[ [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:2.0] ];
animation.timingFunctions = @[ [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear] ];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;

[rotLayer addAnimation:animation forKey:@"test"];
}

如果我使用基本动画而不是关键帧动画,一切都会按预期工作,但如果我在模拟器中运行此代码,它会崩溃并显示以下消息:

 -[CAKeyframeAnimation _copyRenderAnimationForLayer:]: unrecognized selector sent to instance 0x7558870
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAKeyframeAnimation _copyRenderAnimationForLayer:]: unrecognized selector sent to instance 0x7558870'

这是一个启用了 ARC 的新项目。即使将动画设置为属性也不起作用。 QuartzCore 框架也是链接。我做错了什么?

最佳答案

当我运行这段代码时,它工作得很好(一个红色矩形围绕 anchor 旋转, anchor 位于矩形的中心)。

您确定您正确链接了 QuartzCore 框架吗?而你进口了<QuartzCore/QuartzCore.h>进入你的实现文件?看起来像 _copyRenderAnimationForLayer:是 Apple 的内部方法,所以我不质疑它的存在。但是,如果您没有正确链接或导入文件,您的应用程序将不知道该方法存在,然后抛出您看到的异常。

关于iphone - CAKeyframeAnimation 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13879375/

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