UIBezierPath を使用して PieChart を描画しようとしていますが、それにかなり近づいていますが、添付のスクリーンショットでわかるように、問題があります
。使用しているコードは次のとおりです。
-(void)drawRect:(CGRect)rect
{
CGRect bounds = self.bounds;
CGPoint center = CGPointMake((bounds.size.width/2.0), (bounds.size.height/2.0));
NSManagedObject *gameObject = [SCGameManager sharedInstance].gameObject;
int playerNumber = 0;
int totalOfPlayers = [(NSSet*)[gameObject valueForKey:@"playerColors"] count];
float anglePerPlayer = M_PI*2 / totalOfPlayers;
for (NSManagedObject *aPlayerColor in [gameObject valueForKey:@"playerColors"]){
//Draw the progress
CGFloat startAngle = anglePerPlayer * playerNumber;
CGFloat endAngle = startAngle + anglePerPlayer;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:self.frame. size.width/2 startAngle:startAngle endAngle:endAngle clockwise:YES];
UIColor *playerColor = [SCConstants getUIColorForPlayer:[[aPlayerColor valueForKey:@"colorIndex"] intValue]];
[playerColor set];
[path fill];
playerNumber++;
}
}
どうやら、パスを円の中心に移動してから閉じる必要があるようですが、次のコード行を追加すると:
[path addLineToPoint:self.center];
[path closePath];
それは何か奇妙なものを描きます:
私のコードで何が問題になっているのか分かりますか? 私はベジエの専門家ではないので、どんな助けも大歓迎です!
ありがとう!