【发布时间】:2014-07-29 11:20:07
【问题描述】:
我正在添加CAShapeLayer 和一些CABasicAnimation。我希望能够删除图层并再次绘制它,但我无法成功。
- (void)drawRect:(CGRect)rect {
[self drawLayer];
}
- (void)drawLayer {
if (_alayer && _layer.superlayer) {
[_alayer removeFromSuperlayer];
_alayer = nil;
}
_alayer = [[CAShapeLayer alloc] init];
_alayer.path = [self myPath].CGPath;
_alayer.strokeColor = [UIColor redColor].CGColor;
_alayer.fillColor = [UIColor clearColor].CGColor;
_alayer.lineWidth = 2.f;
_alayer.strokeStart = 0.f;
_alayer.strokeEnd = 1.f;
[self.layer addSublayer:_alayer];
// animate
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 2.f;
animation.fromValue = @0.f;
animation.toValue = @1.f;
[_alayer addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"];
}
}
然而,在调用[self setNeedsDisplay]; 之后,即使它在drawLayer 方法中的断点处停止,绘图也不会消失并再次动画。 alayer 被声明为 nonatomic, strong 属性。我做错了什么?
【问题讨论】:
标签: ios objective-c core-animation calayer caanimation