I have a UIView with shapes drawn from a path, inside a loop using values from an array for radius and stroke width. The blends are important, as well as the switch colours (ignore the rgb macro).
What I want to do is animate from the oldShapeRadius
values to the newShapeRadius
affecting the radius of the arc and strokeWidth
of the strokedArc
.
Now I have looked at a lot of examples of Core Animation, but I can't see how it would affect the drawing of the effects as I have below, and how to work with CALayers?
//my UIView
#import "QuartzCore/CALayer.h"
#define degreesToRadians( degrees ) ( ( degrees ) / 180.0 * M_PI )
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.strokeWidth=38.0f;
self.radius=47.0f;
oldShapeRadius=[[NSMutableArray alloc] initWithObjects:[NSNumber numberWithFloat:1], [NSNumber numberWithFloat:1], [NSNumber numberWithFloat:1.0], [NSNumber numberWithFloat:1], nil];
newShapeRadius=[[NSMutableArray alloc] initWithObjects:[NSNumber numberWithFloat:0.6], [NSNumber numberWithFloat:0.9], [NSNumber numberWithFloat:1.0], [NSNumber numberWithFloat:0.5], nil];
}
}
- (void)drawRect:(CGRect)rect
{
for (int i=0; i<4; i++) {
UIColor *shapeColor;
switch (i) {
case 0:
shapeColor=UIColorFromRGB(CATEGORY_COLOR_BLUE);
break;
case 1:
shapeColor=UIColorFromRGB(CATEGORY_COLOR_GREEN);
break;
case 2:
shapeColor=UIColorFromRGB(CATEGORY_COLOR_PINK);
break;
case 3:
shapeColor=UIColorFromRGB(CATEGORY_COLOR_YELLOW);
break;
default:
break;
}
CGMutablePathRef arc = CGPathCreateMutable();
CGPathAddArc(arc, NULL, 160.0f,85, radius*[[oldShapeRadius objectAtIndex:i] floatValue], degreesToRadians(90*i), degreesToRadians(90*(i+1)), NO);
CGPathRef strokedArc =CGPathCreateCopyByStrokingPath(arc, NULL, strokeWidth*[[oldShapeRadius objectAtIndex:i] floatValue], kCGLineCapRound,kCGLineJoinRound,0.0f);
context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeMultiply);
CGContextAddPath(context, strokedArc);
CGContextSetFillColorWithColor(context, shapeColor.CGColor);
CGContextDrawPath(context, kCGPathFill);
}
}
Oh Lords of Stackoverflow may I have some help please. Is High Lord David Rönnqvist around haha. Many thanks in advance.