我正在努力为CAShape图层制作动画但却无法正确使用它。我有一个图层。在UIView子类中,我按如下方式创建CALayer -
CAShapeLayer *shape1 = [CAShapeLayer layer];
shape1.fillColor = [[UIColor clearColor] CGColor];
shape1.strokeColor = [[UIColor purpleColor] CGColor];
CGRect frame1 = CGRectMake(13, 13, self.bounds.size.width - 26, self.bounds.size.height - 26);
shape1.frame = frame1;
shape1.position = CGPointMake(0,0);
shape1.anchorPoint = CGPointMake(self.tableContainerView.frame.size.width/2.0,
self.tableContainerView.frame.size.height/2.0);
shape1.path = [self pathForFrame:frame1];
shape1.strokeEnd = 0.0f;
shape1.lineWidth = 1.0;
[self.layer addSublayer:shape1];
我希望对它进行动画处理,使其在保持中心的同时达到略大于初始值的位置,这样可以创建扩展效果。我的缩放动画代码是 -
CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
//animation2.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation2.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.1)];
animation2.repeatCount = 1;
animation2.removedOnCompletion = NO;
animation2.fillMode = kCAFillModeForwards;
animation2.duration = 10;
animation2.beginTime = CACurrentMediaTime() + 4;
[shape1 addAnimation:animation2 forKey:nil];
任何帮助表示赞赏。提前谢谢。
答案 0 :(得分:0)
您可以使用CAKeyFrameAnimation
更好地控制动画。
您可以这样做:
CAMediaTimingFunction *linearTiming = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
CAKeyframeAnimation *scaleXAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.x"];
scaleXAnimation.duration = 0.300;
scaleXAnimation.values = @[@(0.100), @(0.120), @(0.140), @(0.160)];
scaleXAnimation.keyTimes = @[@(0.000), @(0.333), @(0.667), @(1.000)];
scaleXAnimation.timingFunctions = @[linearTiming, linearTiming, linearTiming];
scaleXAnimation.beginTime = 0;
scaleXAnimation.fillMode = kCAFillModeBoth;
[[self.yourView layer] addAnimation: scaleXAnimation forKey:@"ScaleUp_ScaleX"];
//or if you are subclassing the uiview
[[self layer] addAnimation: scaleXAnimation forKey:@"ScaleUp_ScaleX"];