Welcome to my blog. Thanks.
Dome: github地址
CAAnimation大家族的最后一个组合动画,所有复杂的动画都是有组合动画合成的,也可以说是最简单的。其实没什么可说的,就上一个炫酷的心形组合动画好了,其余的可以在我的代码中看到,简单到你怀疑自己。
GroupAnimation
animations:动画集合数组
draw a heart
- (void)drawRect:(CGRect)rect {
// 间距
CGFloat padding = 4.0;
// 半径(小圆半径)
CGFloat curveRadius = (rect.size.width - 2 * padding)/4.0;
UIBezierPath *heartPath = [UIBezierPath bezierPath];
// 起点
CGPoint tipLocation = CGPointMake(rect.size.width/2, rect.size.height-padding);
// 从起点开始画
[heartPath moveToPoint:tipLocation];
// (左圆的第二个点)
CGPoint topLeftCurveStart = CGPointMake(padding, rect.size.height/2.4);
// 添加二次曲线
[heartPath addQuadCurveToPoint:topLeftCurveStart controlPoint:CGPointMake(topLeftCurveStart.x, topLeftCurveStart.y + curveRadius)];
// 画圆
[heartPath addArcWithCenter:CGPointMake(topLeftCurveStart.x+curveRadius, topLeftCurveStart.y) radius:curveRadius startAngle:M_PI endAngle:0 clockwise:YES];
// (左圆的第二个点)
CGPoint topRightCurveStart = CGPointMake(topLeftCurveStart.x + 2*curveRadius, topLeftCurveStart.y);
// 画圆
[heartPath addArcWithCenter:CGPointMake(topRightCurveStart.x+curveRadius, topRightCurveStart.y) radius:curveRadius startAngle:M_PI endAngle:0 clockwise:YES];
// 右上角控制点
CGPoint topRightCurveEnd = CGPointMake(topLeftCurveStart.x + 4*curveRadius, topRightCurveStart.y);
// 添加二次曲线
[heartPath addQuadCurveToPoint:tipLocation controlPoint:CGPointMake(topRightCurveEnd.x, topRightCurveEnd.y+curveRadius)];
// 设置填充色
[[UIColor redColor] setFill];
[heartPath fill];
heartPath.lineWidth = 2;
heartPath.lineCapStyle = kCGLineCapRound;
heartPath.lineJoinStyle = kCGLineJoinRound;
[[UIColor yellowColor] setStroke];
[heartPath stroke];
}