Skip to content

Instantly share code, notes, and snippets.

@theoknock
Last active November 10, 2021 17:21
Show Gist options
  • Save theoknock/a378183f53ffbd50e4f63c36c0a6f4fa to your computer and use it in GitHub Desktop.
Save theoknock/a378183f53ffbd50e4f63c36c0a6f4fa to your computer and use it in GitHub Desktop.
Matching arc, ellipses or circular path to a touch location
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
^ (UITouch * touch) {
CGPoint center = CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect));
CGPoint tp = [touch preciseLocationInView:touch.view];
CGFloat radius = sqrt(pow(tp.x - center.x, 2.0) + pow(tp.y - center.y, 2.0));
UIBezierPath * bezier_quad_curve = [UIBezierPath bezierPathWithArcCenter:center
radius:radius
startAngle:degreesToRadians(270.0)
endAngle:degreesToRadians(180.0)
clockwise:FALSE];
}([touches.anyObject]);
}
@theoknock
Copy link
Author

This code resizes an arc as a finger is dragged across the screen, its edge matching the touch location precisely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment