1
我正在繪製使用UIBezierPath的六邊形,其中點(或交點)變化由滑塊控制&。 PLS。在這裏看到的截圖: http://postimage.org/image/tq8z8t9qb/使用UIBezierPath繪製六邊形
現在的問題是,當最後一點繪製或移動它已經錯了(我標誌着圈 截圖)。我認爲,這是從貝塞爾路徑的起點/中心點畫出來的。 希望你可以檢查代碼:
- (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];
}
}
請注意,讓我知道什麼是錯的。由於
目前還不清楚你認爲應該做什麼,所以告訴你什麼是錯的幾乎是不可能的。你能上傳你認爲應該是什麼樣子的圖片嗎? – user1118321 2012-03-29 18:49:55
如果您發佈樣本容器應用程序,它會幫助我們。 – Senior 2012-03-29 18:53:53