问题描述
给定一个任意的 UIBezierPath
,我正在寻找一种方法来在该路径长度的一小部分处获得一个点.
示例:
UIBezierPath *path = [UIBezierPath bezierPath];[路径 moveToPoint:CGPointMake(200.0, 200.0)];[路径 addLineToPoint:CGPointMake(200.0, 400.0)];CGPoint p = [路径 pointAtFraction:0.5];
在这种情况下,
p
应该是 {x: 200.0, y: 300.0}
.
我知道可以计算这个简单的例子,但我正在寻找适合任何UIBezierPath
(弧、圆角矩形等)的解决方案
看到 CAShapeLayer
,它基本上依赖于 UIBezierPath
和它的属性 strokeEnd
,我想信息在路径对象的某个地方.但是,UIBezierPath
和 CGPathRef
接口都没有显示任何方法来实现这一点.
我尝试创建一个 CAShapeLayer
,设置 strokeEnd
并从图层中检索 CGPathRef
,但路径保持不变.>
有没有办法(公共 API)来实现这一点?
抱歉耽搁了时间.我实际上在一年多前解决了这个问题,哇.
我在 UIBezierPath
上创建了一个小类别来完成这项工作.此处的 GitHub 存储库
从 1 年前重新阅读我的代码后,我不得不说,当时我过去的编码方式令人震惊:D 缺乏文档令人不安.如果您需要更多信息,请告诉我,我会更新存储库.
Given an arbitrary UIBezierPath
, I'm looking for a way to get a point at a fraction of the length of that path.
Example:
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(200.0, 200.0)];
[path addLineToPoint:CGPointMake(200.0, 400.0)];
CGPoint p = [path pointAtFraction:0.5];
p
should be {x: 200.0, y: 300.0}
in this case.
I'm aware that this simple example could be calculated, but I'm looking for a solution that fits ANY UIBezierPath
(arcs, rounded rects, etc.)
Seeing CAShapeLayer
, which basically lives off UIBezierPath
, and its property strokeEnd
, I suppose the information is somewhere inside the path object. However, neither UIBezierPath
nor CGPathRef
interfaces show any way to achieve this.
I tried creating a CAShapeLayer
, setting the strokeEnd
and retrieving the CGPathRef
from the layer, but the path stays the same.
Is there any way (public API) to achieve this ?
Sorry for the huge delay. I actually solved this more than 1 year ago, wow.
I created a small category on UIBezierPath
which does the job.GitHub Repo here
After re-reading my code from 1 year back I have to say it's quite shocking how I used to code back then :D The lack of documentation is disturbing. If you need more info please let me know and I'll update the repo.
这篇关于UIBezierPath 指向路径的一小部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!