Manipulate UIBezierPath on iOS

I start with a straight line and I would like the user to be able to touch and drag the line so that it curls. In fact, they would have the ability to manipulate a wave-shaped line. I'm not sure about the easiest way to accomplish this technically.

I started by creating an array of cubic curves of UIBezierPaths for the purpose of controlling control points - but it seems that it is impossible to change the control points of UIBezierPaths after drawing them?

Any suggestions regarding the simplest technical approach are appreciated.

+4
source share
1 answer

quadCurve ( ) drawRect, , touchhesBegan . , 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);

}

, touch ... e

+2

Source: https://habr.com/ru/post/1533961/


All Articles