ios layer怎么实现frame动画?
答案:1 悬赏:40 手机版
解决时间 2021-03-17 05:06
- 提问者网友:書生途
- 2021-03-16 18:51
ios layer怎么实现frame动画?
最佳答案
- 五星知识达人网友:神鬼未生
- 2021-03-16 19:40
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];
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];
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯