gpt4 book ai didi

ios - CALayer 子类不对属性更改进行动画处理

转载 作者:可可西里 更新时间:2023-11-01 03:58:18 24 4
gpt4 key购买 nike

我有一个 CALayer 子类,带有浮点 animAngle 作为标记为 @dynamic 的属性。我已经为子类实现了方法 actionForKeyinitWithLayerneedsDisplayForKeydrawInContextactionForKey的定义如下

- (id<CAAction>)actionForKey:(NString *)event {
if([event isEqualToString:@"animAngle"]) {
return [self animationForKey:event];
}
return [super actionForKey:event];
}

- (CABasicAnimation *)animationForKey:(NSString *)key
{
NSString *animValue = [[self presentationLayer] valueForKey:key];// Logs as 0
CABasicAnimation *anim;

if([key isEqualToString:@"animAngle"]) {
anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
anim.repeatCount = HUGE_VAL;
anim.autoreverses = YES;
//anim.fromValue = [[self presentationLayer] valueForKey:key]; // setting animation value from layer property as in here does not work.
anim.fromValue = [NSNumber numberWithFloat:0.5f]; // This works
}
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.duration = 0.11;
return anim;
}

在其他类中:

myCASublayer.animAngle = 0.5f;

返回的 CABasicAnimation 无法正确使用图层“animAngle”属性。我在这里可能做错了什么?

最佳答案

CocoaHeads Session: Rob Napier on Animating Custom Layer Properties是关于自定义动画的一个很好的介绍。

CALayers 讨厌绘制 ;)

关于ios - CALayer 子类不对属性更改进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18289026/

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