I'm facing similar problem as Animating a shape with CoreAnimation
I have a custom UIView
MyUIView
- (void)drawRect:(CGRect)rect {
// Right here, I might also draw some triangle, circle which I do not wish
// to be animated.
// ...
// Calculate minX, minY, ... based on rect and self->value.
// ...
// Draw a rounded rectangle based on minX, minY, ...
// The x-location of rounded rectangle will be different for difference self->value
CGContextMoveToPoint(context, minx, midy);
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
...
...
CGContextDrawPath(context, kCGPathFillStroke);
}
// Usually trigger by controller via button clicked
- (void) setValueViaButtonClicked:(double) value {
self->currentValue = value;
dispatch_async(dispatch_get_main_queue(), ^{
[self setNeedsDisplay];
});
}
Currently, whenever I click the button with a new value different from old value, I can see the rounded rectangle moved from old position to new position, but without animation.
I would like to have animation, only during explicit button click. For most of the examples I had seen, the animation code is performed within controller, by
- Animation is done through Layer and CGPathCreateMutable
- The creation of Layer and CGPathCreateMutable, is performed in view controller.
I was wondering, how am I possible to perform the above tasks through MyUIView
's setValueViaButtonClicked
? As without proper rect
information from drawRect, how am I going to configure information for paths created from CGPathCreateMutable
?