Is it possible to animate a UIView
's CoreGraphics content?
Say I have a UIView
subclass called MyView
that implements the drawRect:
method like so:
- (void) drawRect: (CGRect) rect {
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(c, someColor);
CGContextSetLineWidth(c, someWidth);
CGContextMoveToPoint(c, leftOfMyUIView, topOfMyUIView);
CGContextAddLineToPoint(c, leftOfMyUIView, bottomOfMyUIView);
CGContextStrokePath(c);
}
In other words - it draws a vertical line down the left hand side of my subclass of UIView. Is there an easy way to now animate this UIView so that the line moves from the left side to the right side of the view? I would like it to 'drift' from left to right.
To be clear - for reasons I will not go into I cannot move/animate the instance of MyView
. The best solution I can think of using is to add a new UIView
subclass. Something like LineView extends UIView
and then make LineView the exact dimensions of the line I want to draw, fill it using its own drawRect
method and then add an instance of LineView
to MyView
as a subview. This would allow me to animate the position of the LineView
object using an animation block, but seems overly complicated to achieve something so simple.