ios - UIBezierPath - 你能“剪辑”一个吗?
问题描述
假设您已经构建了一个 UIBez:
现在我想“剪辑”它,也许用这个矩形:
因此,在示例中,我想要的最终路径是:
(或者在示例中,您可以在右侧“减去”一个矩形,在底部“减去”一个。)
iOS 工具包是否包含用于 UIBezierPath 构造的此功能?
我认为答案是“不”,但这是无法通过谷歌搜索到的事情之一,因为您获得了不相关的 QA。所以我找不到答案。
请注意- 这与简单地“添加一个洞”完全不同,因为这是一种司空见惯的使用.append
方式(例如https://stackoverflow.com/a/57514286/294884)
解决方案
There is no built-in clipping of paths (and definitely no auto-closing of clipped paths, either).
Beyond the “adding a hole” technique that you’ve mentioned, the other approach is just masking/clipping it. And I know you know this, but for the sake of future readers, the built-in clipping/masking is only available within a graphics context (or the mask
of a CALayer
). For example, if you have a CAShapeLayer
, you can set its mask
(to the rect illustrated by the dashed rectangle below, for example):
Obviously, this approach can’t “close” the path(s) that have been clipped.
However, if your paths consist of a series of line segments, you theoretically could write your own routine to iterate through those line segments looking for intersections with your rectangular clipping mask (as well as detecting whether they’re contained by the clipping mask at all). If you search for “<a href="https://stackoverflow.com/search?q=uibezierpath%20intersection">UIBezierPath intersection”, you will see some relevant examples. Even then, you’ll have interesting edge cases about how to algorithmically close your paths.
推荐阅读
- laravel - 如何更改 Laravel 集合输出中的某些值
- pandas - 我正在尝试将 DataFrame 中的某些列从浮点数转换为整数
- vue.js - Vue Capacitor Ionic 4 Uncaught TypeError:无法重新定义属性:队列
- php - 提交时表单未发送电子邮件。我错过了什么?
- python-3.x - ValueError:传递了与“cell.state_size”不兼容的“initial_state”
- android - 如果我使用图书馆,我必须对用户说
- java - JSON 响应已使用 Jackson 和 JAX-RS 异常映射器转义引号
- powershell - 是否可以在 Powershell 中自定义详细消息前缀?
- tensorflow - 在同一台机器上安装 Nvidia CUDA ver10 会破坏 CUDA ver9 吗?
- r - 使用一组断点将数据分位数