如何从顶部开始绘制圆圈 [英] How to draw a circle starting at the top

查看:134
本文介绍了如何从顶部开始绘制圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些使用CGPath绘制弧的示例代码。我已经浏览了一下并找到了文档,但我似乎无法直观地看到我在使用MoveToPoint,AddLineToPoint等方面的情况。我无法看到代码在做什么我可以只是看到结果。

I'm working with some example code that draws an arc using CGPaths. I've had a look around and have found documentation but I just can't seem to visualize in my head whats going on in terms of using MoveToPoint, AddLineToPoint etc. I can't 'see' what the code is doing I can just see the result.

例如,下面的代码从3点钟位置开始绘制一个完整的360度圆弧。对于我的生活,我无法弄清楚如何让它从12点钟位置开始实际旋转视图 - 90度。

For example the code below draws an arc a full 360 degrees beginning from the 3 o clock position. For the life of me I can't figure out how to make it begin from the 12 o clock position with actually rotating the view - 90 degrees.

有人可以帮助我弄清楚这段代码以及我将如何改变它以实现从12点开始,最好试图解释整个路径是如何工作的。或者也许在线指向我的视觉资源?

Could somebody help me figure out this code and how I would change it to achieve the beginning from 12 o'clock, preferably trying to explain how this whole paths things works. Or maybe point me to a visual resource online?

- (void)drawPathWithArc:(CGFloat)arc {
    CGMutablePathRef thePath = CGPathCreateMutable();
    CGPathMoveToPoint(thePath, NULL, 100.f, 100.f);
    CGPathAddLineToPoint(thePath, NULL, 200.f, 100.f);
    CGPathAddArc(thePath, NULL, 100.f, 100.f, 100.f, 0.f, (360* M_PI)/180, NO);
    CGPathCloseSubpath(thePath);
    shapeLayer_.path = thePath;
    CGPathRelease(thePath);
}


推荐答案

路径真的不是那么难在视觉上理解。基本上所有路径都是连接笛卡尔平面上定义iphone屏幕的两个点的线。

Paths really are not that hard to understand visually. Basically all a path is is a line connecting two points on the cartesian plane that defines the iphone's screen.

当你移动ToPoint时,它会将路径的当前点设置为指定的点。

When you moveToPoint it sets the current point of the path to the specified point.

当你添加了LineToPoint时,它会从当前点到指定点绘制一条直线。

When you addLineToPoint it draws a straight line from the current point to the specified point.

当你addCurveToPoint时,它会根据某些切线和控制点从当前点到指定点绘制一条曲线。

When you addCurveToPoint it draws a curved line from the current point to the specified point based on certain tangents and control points.

等等。我建议在CGPaths上阅读apple文档,以便更好地理解每个函数的作用。

And so on. I would recommend reading apples documentation on CGPaths in order to better understand what each function is doing.

http://developer.apple.com/library/mac/#documentation/graphicsimaging/Reference/CGPath/Reference/reference.html

至于你的问题是从12而不是3开始,只需阅读CGPathAddArc函数的文档。

As far as your question goes to making this start at 12 instead of 3 simply read the documentation for the CGPathAddArc function.

您需要做的是更改当前代码:

What you need to do is change your current code:

CGPathAddArc(thePath, NULL, 100.f, 100.f, 100.f, 0.f, (360* M_PI)/180, NO);

to:

CGPathAddArc(thePath, NULL, 100.f, 100.f, 100.f, -M_PI_2, M_PI_2*3, NO);

所有这一切都是将起始角度改为-90度(所有角度均以弧度为单位)水平)和结束角度为270度。

All this is doing is changing the starting angle to -90 degrees (all angles are measured in radians from the horizontal) and the ending angle to 270 degrees.

希望这会有所帮助。
干杯,

Hope this helps. Cheers,

Brenton。

这篇关于如何从顶部开始绘制圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆