Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在目标C中画一个饼_Objective C_Cocoa_Graphics - Fatal编程技术网

Objective c 在目标C中画一个饼

Objective c 在目标C中画一个饼,objective-c,cocoa,graphics,Objective C,Cocoa,Graphics,我用下面的代码在目标C中画了一条弧 [newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle]; 现在我想画两条从中心到弧两端的线。我该怎么做?我可以用以下代码绘制一面: [newPath lineToPoint:center]; 但是另一面呢。我现在没有机会测试它,但是你可以试试这样的东西 #import "math.h"

我用下面的代码在目标C中画了一条弧

    [newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle];
现在我想画两条从中心到弧两端的线。我该怎么做?我可以用以下代码绘制一面:

    [newPath lineToPoint:center];

但是另一面呢。

我现在没有机会测试它,但是你可以试试这样的东西

#import "math.h"

[newPath moveToPoint:center];
[newPath addLineToPoint:CGPointMake(center.x + radius * cos(endAngle * M_PI / 180),
                                    center.y + radius * sin(endAngle * M_PI / 180))];

[newPath moveToPoint:center];
[newPath addLineToPoint:CGPointMake(center.x + radius * cos(startAngle * M_PI / 180),
                                    center.y + radius * sin(startAngle * M_PI / 180))];
绘制饼图最简单的方法是使用以下事实:
appendBezierPathWithArcWithCenter:…
绘制饼图 从当前点到圆弧起点的直线:

// Start at the center of the circle:
[newPath moveToPoint:center];
// This draws a line from the center to the starting point of the arc AND the arc:
[newPath appendBezierPathWithArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle];
// Closing the path draws a line from the end point of the arc back to the center:
[newPath closePath];

使用三角学计算圆弧的起点,然后当光标位于中心时,
[newPath lineToPoint:startingPoint]
。在iOS SDK中,等效方法为addArcWithCenter: