【发布时间】:2012-03-18 20:59:45
【问题描述】:
我正在尝试为 UIView 子类中的 UIBeizerPath(在我的示例中为三角形)的绘制设置动画。但是,整个子视图是动画而不是形状。
我的动画有什么遗漏吗?
- (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 是的,我想为每个点的绘图设置动画,以便三角形看起来像动画
标签: uiview core-animation core-graphics cakeyframeanimation