iphone - UIBezierPath 减去路径

通过使用 [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/

相关文章:

iphone - 如何删除应用程序指定目录中的所有文件?

ios - 从 View 中删除所有子图层

ios - 如何从 CGPoint 和 CGSize 创建 CGRect?

objective-c - 检测平移手势结束

objective-c - 从 UIScrollView 中删除所有 subview ?

ios - 如何删除 xcode 5 中的旧配置文件?

objective-c - 奇怪的错误 NSAssert

ios - MKMapView MKPointAnnotation 点击​​事件

objective-c - 分组的 UITableView 在底部有 20px 的额外填充

objective-c - Interface Builder 中的 IBOutletCollect