bezierPathWithRoundedRect: -- 奇怪的渲染人工制品

bezierPathWithRoundedRect: -- odd rendering artefact

我正在绘制一个带有几个圆角的简单矩形:

UIBezierPath * p = [UIBezierPath bezierPathWithRoundedRect:outline
                                         byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
                                               cornerRadii:CGSizeMake(8, 8)];

奇怪的是,左上角似乎不完整 - 缺少一个小缺口:

奇怪的是 - 如果添加 [p close] - 问题就消失了。现在文档表明:

This method creates a closed subpath, proceeding in a clockwise direction (relative to the default coordinate system) as it creates the necessary line and curve segments.

所以我想知道哪里出了问题?我是不是误解了文档 - 还是我的代码中有微妙的 bug/issue?

为了完整起见,有问题的代码是

- (void)drawRect:(CGRect)rect {
CGRect outline = CGRectInset(self.bounds, 4, 4);
UIBezierPath * p = [UIBezierPath bezierPathWithRoundedRect:outline
                                         byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
                                               cornerRadii:CGSizeMake(8, 8)];
// [p closePath];
[[UIColor blackColor] setStroke];
[p setLineWidth:4];
[p stroke];
....

看起来最后的路径实际上并没有闭合,这可能是一个错误(值得 filing if so)—basically, since it doesn’t know the beginning and end points are connected, you’re seeing end caps (which by default 只绘制到路径的确切末端)而不是一条连续的线。听起来您的 -close 解决方案有效;随它去吧。