通过使用 [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]
,我可以创建圆形 View ,例如:
我如何从这条路径(或其他方式)中减去另一条路径,以创建这样的路径:
有什么办法可以做这样的事情吗? 伪代码:
UIBezierPath *bigMaskPath = [UIBezierPath bezierPathWithRoundedRect:bigView.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(18, 18)];
UIBezierPath *smallMaskPath = [UIBezierPath bezierPathWithRoundedRect:smalLView.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(18, 18)];
UIBezierPath *finalPath = [UIBezierPath pathBySubtractingPath:smallMaskPath fromPath:bigMaskPath];
最佳答案
其实在大多数情况下有一个更简单的方法,例如在 Swift 中:
path.append(cutout.reversing())
这是可行的,因为默认的填充规则是 non-zero winding rule .
https://stackoverflow.com/questions/8859285/