Ios 使用值数组对CGPath进行动画
我有一个UIView,其中的形状是从一条路径绘制的,在一个循环中使用数组中的半径和笔划宽度值。混合色以及切换颜色都很重要(忽略rgb宏) 我想做的是将Ios 使用值数组对CGPath进行动画,ios,objective-c,quartz-2d,caanimation,Ios,Objective C,Quartz 2d,Caanimation,我有一个UIView,其中的形状是从一条路径绘制的,在一个循环中使用数组中的半径和笔划宽度值。混合色以及切换颜色都很重要(忽略rgb宏) 我想做的是将oldShapeRadius值设置为newShapeRadius的动画,从而影响strokedArc的圆弧半径和strokeWidth 现在我已经看了很多核心动画的例子,但是我看不出它会如何影响下面的效果的绘制,以及如何使用CALayers //my UIView #import "QuartzCore/CALayer.h" #define deg
oldShapeRadius
值设置为newShapeRadius
的动画,从而影响strokedArc
的圆弧半径和strokeWidth
现在我已经看了很多核心动画的例子,但是我看不出它会如何影响下面的效果的绘制,以及如何使用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);
}
}
//我的UIView
#导入“QuartzCore/CALayer.h”
#定义度弧度(度)((度)/180.0*M_-PI)
-(id)initWithFrame:(CGRect)帧
{
self=[super initWithFrame:frame];
如果(自我){
自行程宽度=38.0f;
自半径=47.0f;
oldShapeRadius=[[NSMutableArray alloc]initWithObjects:[NSNumber numberWithFloat:1],[NSNumber numberWithFloat:1],[NSNumber numberWithFloat:1.0],[NSNumber numberWithFloat:1],无];
newShapeRadius=[[NSMutableArray alloc]initWithObjects:[NSNumber numberWithFloat:0.6],[NSNumber numberWithFloat:0.9],[NSNumber numberWithFloat:1.0],[NSNumber numberWithFloat:0.5],无];
}
}
-(void)drawRect:(CGRect)rect
{
对于(int i=0;我给你指出这一点,这大约是你试图完成的90%,最终的混合步骤可以在这一步之后完成。是的,我已经开始了,但现在我正在尝试添加混合。!谢谢@Can