如何使用两个单独的CABasicAnimations同时为同一属性设置动画?
例如,两个CABasicAnimations,都是animate position.y.
第一个动画将是反弹(从100到300,持续时间= 1,autoreverse = yes,repeatcount = 10)
第二个动画将是一个慢速滚动(100,持续时间= 10)
我看到的行为是,如果第一个动画正在进行中,我使用:
[pickle.layer addAnimation:[self makescrollanimation] forKey:@"scrollit"];
添加第二个...第二个被忽略.
我知道第二个动画是有效的,因为如果我从第二个动画开始,那么第一个动画将被忽略.
谢谢 - 马特
如果我理解正确,你希望视图在整个弹跳动作缓慢向下移动时上下弹跳.您可以通过使用其添加属性制作动画添加剂来实现此目的.例如:
CABasicAnimation *bounceAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"]; bounceAnimation.duration = 1; bounceAnimation.fromValue = [NSNumber numberWithInt:100]; bounceAnimation.toValue = [NSNumber numberWithInt:300]; bounceAnimation.repeatCount = 10; bounceAnimation.autoreverses = YES; bounceAnimation.fillMode = kCAFillModeForwards; bounceAnimation.removedOnCompletion = NO; bounceAnimation.additive = YES; [view.layer addAnimation:bounceAnimation forKey:@"bounceAnimation"]; CABasicAnimation *scrollAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"]; scrollAnimation.duration = 10; scrollAnimation.fromValue = [NSNumber numberWithInt:0]; scrollAnimation.toValue = [NSNumber numberWithInt:100]; scrollAnimation.fillMode = kCAFillModeForwards; scrollAnimation.removedOnCompletion = NO; scrollAnimation.additive = YES; [view.layer addAnimation:scrollAnimation forKey:@"scrollAnimation"];
如果我正确地阅读你的问题,应该完成你想要的动画.应该能够在反弹动画期间的任何时刻触发滚动动画.