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];
}
Dome: github地址