我正在使用 UIBezierPath 绘制一个六边形,其中它的点(或交叉点)变化并由滑块控制。请。在此处查看屏幕截图:http: //postimage.org/image/tq8z8t9qb/
现在的问题是,当最后一个点被绘制或移动时,它已经是错误的了(我已将屏幕截图标记为 circle )。我认为,它从贝塞尔路径的原点/中心点画了一条额外的线。希望您可以检查代码:
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
CGPoint center = CGPointMake(150.0, 150.0);
// line
UIBezierPath *polyPath = [UIBezierPath bezierPath];
polyPath.lineWidth = 5;
[polyPath moveToPoint:CGPointMake(center.x, center.y + 60.0)];
for (int i = 1; i <= 6; ++i) {
CGFloat x, y;
NSNumber *oNumb = [[self aIndexValues] objectAtIndex:i-1];
fXValue_ = [oNumb floatValue];
x = fXValue_ * sinf(i * 2.0 * M_PI / 6.0);
y = fXValue_ * cosf(i * 2.0 * M_PI / 6.0);
[polyPath addLineToPoint:CGPointMake(center.x + x, center.y + y)];
}
[polyPath closePath];
[[UIColor redColor] setStroke];
[polyPath stroke];
// circle point
for(int i = 1; i <= 6; ++i) {
CGFloat x, y;
NSNumber *oNumb = [[self aIndexValues] objectAtIndex:i-1];
fXValue_ = [oNumb floatValue];
x = fXValue_ * sinf(i * 2.0 * M_PI / 6.0);
y = fXValue_ * cosf(i * 2.0 * M_PI / 6.0);
UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(center.x + x - 6, center.y + y - 6, 15, 15)];
circle.lineWidth = 5;
[[UIColor whiteColor] setFill];
[circle fill];
}
}
请。让我知道出了什么问题。谢谢