gpt4 book ai didi

ios - iOS 上的 UIBezierPath 操作

转载 作者:可可西里 更新时间:2023-11-01 05:54:19 24 4
gpt4 key购买 nike

我从一条直线开始,我希望用户能够触摸并拖动这条线,使其弯曲。实际上,他们将有能力将线操纵成波浪形。我不确定在技术上实现这一目标的最简单方法。

我首先创建了一个三次曲线的 UIBezierPaths 数组,目的是操纵控制点 - 但似乎无法在绘制 UIBezierPaths 的控制点后更改它们?

感谢任何有关最简单技术方法的建议。

最佳答案

可以在drawRect中以变量为控制点绘制quadCurve(一个控制点的贝塞尔曲线),然后在touchesBegan方法中更新控制点如下。注意需要用setNeedsDisplay重绘

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
controlPoint = [[touches anyObject] locationInView:self];
[self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 1.0);

CGContextMoveToPoint(context, 0, 320);
CGContextAddQuadCurveToPoint(context, controlPoint.x, controlPoint.y, 320, 200);
CGContextStrokePath(context);

}

如果你有多个控制点,那么在 touchesMoved 方法中需要一些视觉元素和额外的逻辑...... e

关于ios - iOS 上的 UIBezierPath 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22720179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com