0

半径とストローク幅の配列からの値を使用して、ループ内にパスから描画された形状を持つ UIView があります。色の切り替えだけでなく、ブレンドも重要です (rgb マクロは無視してください)。

私がやりたいことは、oldShapeRadius値から円弧とのnewShapeRadius半径に影響を与えるようにアニメーション化することです。strokeWidthstrokedArc

Core Animation の例をたくさん見てきましたが、以下のように効果の描画にどのように影響するかわかりません。

//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);    
}
}

ああ、Stackoverflow の主よ、助けてください。ハイ・ロード・デビッド・ロンクヴィストです(笑)。よろしくお願いします。

4

0 に答える 0