UIView 하위 클래스에서 UIBeizerPath (내 예제에서는 삼각형)의 드로잉에 애니메이션을 적용하려고합니다. 그러나 전체 하위 뷰는 모양 대신 애니메이션으로 표시됩니다.CoreGraphics를 그리는 방법 CAKeyframeAnimation을 사용하여 도형 그리기
애니메이션이 누락 되었습니까?
- (void)drawRect:(CGRect)rect {
CAShapeLayer *drawLayer = [CAShapeLayer layer];
drawLayer.frame = CGRectMake(0, 0, 100, 100);
drawLayer.strokeColor = [UIColor greenColor].CGColor;
drawLayer.lineWidth = 4.0;
[self.layer addSublayer:drawLayer];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0,0)];
[path addLineToPoint:CGPointMake(50,100)];
[path addLineToPoint:CGPointMake(100,0)];
[path closePath];
CGPoint center = [self convertPoint:self.center fromView:nil];
[path applyTransform:CGAffineTransformMakeTranslation(center.x, center.y)];
[[UIColor redColor] set];
[path fill];
[[UIColor blueColor] setStroke];
path.lineWidth = 3.0f;
[path stroke];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 4.0f;
pathAnimation.path = path.CGPath;
pathAnimation.calculationMode = kCAAnimationLinear;
[drawLayer addAnimation:pathAnimation forKey:@"position"];
}
수단 "는 UIBezierPath의 드로잉 애니메이션"정확히 설명한다. 당신은 개별 세그먼트를 차례로 그리기를 원합니 까? –
@kurt yes 삼각형이 움직이는 것처럼 보이도록 각 점의 그림을 애니메이션화하려고합니다. –