为什么连线不会四舍五入?

Ano*_*mie 10 core-graphics ios

我有以下代码:

- (void)drawRect:(CGRect)rect {
    CGContextRef c = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(c, [UIColor blackColor].CGColor);
    CGContextFillRect(c, rect);

    CGContextSetLineJoin(c, kCGLineJoinRound);
    CGContextSetLineCap(c, kCGLineCapRound);
    CGContextSetLineWidth(c, 50.0);

    CGContextSetStrokeColorWithColor(c, [UIColor redColor].CGColor);
    CGContextBeginPath(c);
    CGContextMoveToPoint(c, 60, 60);
    CGContextAddLineToPoint(c, 60, 250);
    CGContextAddLineToPoint(c, 60, 249);
    CGContextStrokePath(c);

    CGContextSetStrokeColorWithColor(c, [UIColor blueColor].CGColor);
    CGContextBeginPath(c);
    CGContextMoveToPoint(c, 160, 60);
    CGContextAddLineToPoint(c, 160, 250);
    CGContextAddLineToPoint(c, 160.01, 249);
    CGContextStrokePath(c);
}
Run Code Online (Sandbox Code Playgroud)

这会生成以下输出:

输出代码

有没有一个很好的理由,红色的底部边缘不圆?或者它是Core Graphics中的一个错误,当该行完全翻倍时?

Mor*_*ast 5

绝对是一个错误。如果您尝试向路径添加另一行,则可以看到Core Graphics无法处理它。

CGContextMoveToPoint(c, 60.0, 60.0);
CGContextAddLineToPoint(c, 60.0, 250.0);
CGContextAddLineToPoint(c, 60.0, 249.0);
CGContextAddLineToPoint(c, 60.0, 250.0);
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

好像创建圆角帽和连接的蒙版在翻倍时被反转了。