I've got a CAShapeLayer subclass which features two properties, a startPoint and an endPoint. These properties aren't directly drawn into the context but rather used to alter the path property, similar to the transform, position and bounds properties.
Here's the code of the whole layer
-(void)setStartPoint:(CGPoint)startPoint {
if (!CGPointEqualToPoint(_startPoint, startPoint)) {
_startPoint = startPoint;
[self reloadPath];
}
}
-(void)setEndPoint:(CGPoint)endPoint {
if (!CGPointEqualToPoint(_endPoint, endPoint)) {
_endPoint = endPoint;
[self reloadPath];
}
}
-(id)initWithLayer:(CRPathLayer*)layer {
self = [super initWithLayer:layer];
if (self && [layer isKindOfClass:[CRPathLayer class]]) {
self.startPoint = layer.startPoint;
self.endPoint = layer.endPoint;
}
return self;
}
+(BOOL)needsDisplayForKey:(NSString *)key {
if ([key isEqualToString:NSStringFromSelector(@selector(startPoint))] || [key isEqualToString:NSStringFromSelector(@selector(endPoint))]) {
return YES;
}
return [super needsDisplayForKey:key];
}
-(void)reloadPath {
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.startPoint.x, self.startPoint.y);
CGPathAddLineToPoint(path, NULL, self.endPoint.x, self.endPoint.y);
self.path = path;
CGPathRelease(path);
}
However there's a problem. I need to animate one of the two new properties (start- or endPoint). I'm aware of the fact that I could just animate the path property directly, however this is not what I want to achieve. I'm obviously missing something in the implementation. When I try to animate it using a CABasicAnimation nothing happens at all.
Can anybody help me out here? Thanks in advance.