中易网

ios 怎么讲一个动画加到多个layer 上

答案:1  悬赏:40  
解决时间 2021-01-10 17:20
  • 提问者网友:活着好累
  • 2021-01-10 07:13
ios 怎么讲一个动画加到多个layer 上
最佳答案
  • 二级知识专家网友:执傲
  • 2021-01-10 08:49
frame没有关键帧,可以用动画组实现
CGRect frame = itemLayer.frame;
CABasicAnimation *aniBounds = [CABasicAnimation animationWithKeyPath:@"bounds"];
aniBounds.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, CGRectGetWidth(frame), 0)];
aniBounds.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame))];

CABasicAnimation *aniAnchorPoint = [CABasicAnimation animationWithKeyPath:@"anchorPoint"];
aniAnchorPoint.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 1)];
aniAnchorPoint.toValue = [NSValue valueWithCGPoint:CGPointMake(0, 1)];

CABasicAnimation *aniPosition = [CABasicAnimation animationWithKeyPath:@"position"];
aniPosition.fromValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(frame), _chartHeight+3)];
aniPosition.toValue = [NSValue valueWithCGPoint:CGPointMake(CGRectGetMinX(frame), positionYto)];

CAAnimationGroup *anis = [CAAnimationGroup animation];
anis.animations = @[aniAnchorPoint,aniBounds,aniPosition];
anis.duration = 0.4;
anis.removedOnCompletion = NO;
anis.fillMode=kCAFillModeForwards;
[itemLayer addAnimation:anis forKey:nil];
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息