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

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


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

objective-c - bezierPathWithRoundedRect:—奇数渲染伪像-LMLPHP

奇怪的是-如果添加[p close]-这个问题就解决了。现在文档建议:


  此方法创建一个封闭的子路径,按顺时针方向进行
  创建时的方向(相对于默认坐标系)
  必要的线段和曲线段。


所以我想知道哪里出了问题?我是对文档的误解吗?还是我的代码中存在细微的错误/问题?

为了完整起见,违规代码为

- (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)-基本上,由于它不知道起点和终点已连接,因此您会看到端盖( by default仅绘制到路径的确切末端),而不是实线。听起来您的-close解决方案有效;一起去。

关于objective-c - bezierPathWithRoundedRect:—奇数渲染伪像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33395328/

10-08 20:34