私はCore Graphicsを初めて使用し、円とその周りにすべての方向に線を描き、円から光線が出ているようなアニメーションを作成したいと考えています。の
円のすべての方向に線のアニメーション効果を実現する方法として提案してください。
円を描くためのこれまでのコードは次のとおりです。
- (void)drawRect:(CGRect)iRect
{
// Drawing code
CGContextRef aContext = UIGraphicsGetCurrentContext();
[self drawMeWithContext:aContext withRect:iRect];
[self drawBadgeGradientWithContext:aContext withRect:iRect];
}
- (void)drawMeWithContext:(CGContextRef)iContext withRect:(CGRect)iRect {
CGContextSaveGState(iContext);
CGFloat aRadius = CGRectGetMaxY(iRect) * kBadgeCornerRadius;
CGFloat aBuffer = CGRectGetMaxY(iRect) * kScreenBuffer;
CGFloat aMaxX = CGRectGetMaxX(iRect) - aBuffer;
CGFloat aMaxY = CGRectGetMaxY(iRect) - aBuffer;
CGFloat aMinX = CGRectGetMinX(iRect) + aBuffer;
CGFloat aMinY = CGRectGetMinY(iRect) + aBuffer;
CGContextBeginPath(iContext);
CGContextSetFillColorWithColor(iContext, [_MyColor CGColor]);
CGContextAddArc(iContext, aMaxX - aRadius, aMinY + aRadius, aRadius, M_PI + M_PI/2, 0, 0);
CGContextAddArc(iContext, aMaxX - aRadius, aMaxY - aRadius, aRadius, 0, M_PI/2, 0);
CGContextAddArc(iContext, aMinX + aRadius, aMaxY - aRadius, aRadius, M_PI/2, M_PI, 0);
CGContextAddArc(iContext, aMinX + aRadius, aMinY + aRadius, aRadius, M_PI, M_PI + M_PI/2, 0);
CGContextClosePath(iContext);
CGContextFillPath(iContext);
CGContextRestoreGState(iContext);
}
- (void)drawBadgeGradientWithContext:(CGContextRef)iContext withRect:(CGRect)iRect {
CGContextSaveGState(iContext);
CGFloat aRadius = CGRectGetMaxY(iRect) * kBadgeCornerRadius;
CGFloat aBuffer = CGRectGetMaxY(iRect) * kScreenBuffer;
CGFloat aMaxX = CGRectGetMaxX(iRect) - aBuffer;
CGFloat aMaxY = CGRectGetMaxY(iRect) - aBuffer;
CGFloat aMinX = CGRectGetMinX(iRect) + aBuffer;
CGFloat aMinY = CGRectGetMinY(iRect) + aBuffer;
CGContextBeginPath(iContext);
CGContextAddArc(iContext, aMaxX - aRadius, aMinY + aRadius, aRadius, M_PI+(M_PI/2), 0, 0);
CGContextAddArc(iContext, aMaxX - aRadius, aMaxY - aRadius, aRadius, 0, M_PI/2, 0);
CGContextAddArc(iContext, aMinX + aRadius, aMaxY - aRadius, aRadius, M_PI/2, M_PI, 0);
CGContextAddArc(iContext, aMinX + aRadius, aMinY + aRadius, aRadius, M_PI, M_PI+M_PI/2, 0);
CGContextClip(iContext);
size_t aNumberOfLocations = 2;
CGFloat aLocations[2] = {0.0, 0.5};
// CGFloat aComponents[8] = {0.98, 0.96, 0.98, 1.0, 0.698, 0.016, 0.075, 1.0};
CGColorSpaceRef aColorSpace;
CGGradientRef aGradient;
aColorSpace = CGColorSpaceCreateDeviceRGB();
aGradient = CGGradientCreateWithColorComponents (aColorSpace, _MyColorComponent, aLocations, aNumberOfLocations);
CGColorGetComponents([[UIColor redColor] CGColor]);
CGColorGetComponents([[UIColor whiteColor] CGColor]);
CGPoint aStartPoint;
CGPoint anEndPoint;
aStartPoint.x = 0;
aStartPoint.y = 0;
anEndPoint.x = 0;
anEndPoint.y = aMaxY;
CGContextDrawLinearGradient (iContext, aGradient, aStartPoint, anEndPoint, 0);
CGColorSpaceRelease(aColorSpace);
CGGradientRelease(aGradient);
CGContextRestoreGState(iContext);
}