Я рисую шестиугольник, используя UIBezierPath, в котором его точки (или пересечения) изменяются и управляются ползунком. Pls. смотрите скриншот здесь:
http://postimage.org/image/tq8z8t9qb/
Проблема сейчас в том, что когда последняя точка нарисована или сдвинута, это уже неправильно (я пометил скриншот в кружке
). Я думаю, что нарисована дополнительная линия от начальной точки / центральной точки пути Безье.
Надеюсь, вы можете проверить код:
- (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];
}
}
Pls. дайте мне знать, что не так. Спасибо