- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 CALayer 子类内的绘图函数内绘制圆弧时遇到问题。该绘图函数的实现如下:
-(void)drawInContext:(CGContextRef)ctx
{
CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
CGFloat radius = MIN(center.x, center.y);
CGContextBeginPath(ctx);
CGContextAddArc(ctx, center.x, center.y, radius, DEG2RAD(0), DEG2RAD(90), YES);
CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(ctx, 5);
CGContextDrawPath(ctx, kCGPathStroke);
}
这里并没有太多突破性的东西,但奇怪的是它是逆时针绘制弧线,尽管我指定它应该是顺时针的。相反,当我为 clockwise 参数指定 NO 时,它会顺时针绘制圆弧。我对翻转坐标系进行了一些研究,并认为这可能是这里的问题所在,但我不想只是硬编码与我的意思相反的 bool 参数。有关如何解决此问题的任何建议?
谢谢!
最佳答案
这确实是由于 UIKit 与 Quartz 的坐标系翻转所致。来自docs for CGContext :
The clockwise parameter determines the direction in which the arc is created; the actual direction of the final path is dependent on the current transformation matrix of the graphics context. For example, on iOS, a UIView flips the Y-coordinate by scaling the Y values by -1. In a flipped coordinate system, specifying a clockwise arc results in a counterclockwise arc after the transformation is applied.
您可以通过使用转换矩阵来翻转您的上下文,从而在您的代码中缓解这种情况:
CGContextTranslateCTM(ctx, 0.0, self.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
您可能想在完成绘图后将其翻转回来,即
CGContextSaveGState(ctx);
CGContextTranslateCTM(ctx, 0.0, self.bounds.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
// Draw...
CGContextRestoreGState(ctx);
关于ios - CGContextAddArc逆时针而不是顺时针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16974258/
我正在 Eclipse 上学习 clojure(逆时针插件)。 当我在 Eclipse 中单击“运行”时(就像我用 Java 做的那样)我没有 只有控制台打开,但这个“REPL”窗口。为什么有必要 它
是否可以查看您在 Eclipse 中逆时针 REPL 中输入的内容的历史?就像按向上箭头或 ctrl-p 或其他各种在其他 repl 中起作用的东西一样? 谢谢! -菲利普 最佳答案 是的,很抱歉没有
在 Eclipse+Counterclock 中,当我想连接到 REPL 时,对话框告诉我可以通过 HTTP 使用 nREPL: 如何设置? 这是否以某种方式连接到 drawbridge ?尽管 le
我使用的是来自 WWDC 的 Apple CircleLayout 的略微修改版本:https://github.com/mpospese/CircleLayout . 我当前的代码在顶部绘制第一个元
我有一组可能形成凹多边形的无序顶点。现在我想按顺时针或逆时针顺序排列它们。 An answer here建议执行以下步骤: 找到多边形中心 计算角度 按角度排序点 这显然只适用于凸多边形,当点形成凹多
我想知道与 Emacs 相比,Eclipse 的逆时针插件有哪些限制。 Eclipse 不会提供哪些 Lisp(和 Clojure)魔法? - 更新 - 我知道 Emacs 会有更多功能、快捷方式、各
我是一名优秀的程序员,十分优秀!