Draw a smooth line with a finger touch on the iPhone

How to make a smooth line with finger movement / touch on iPhone? I have the following code, but it is not smooth. For example, it makes corners / turns when I try to make a circle. I think I need to use OpenGL. Any ideas? sample code? textbooks?

Thank!

UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
+3
source share
3 answers

I ended up using Open GL and particle. A good example for this is the Apple GLPaint code example.

+5
source

Add this to your code to smooth the lines between points

CGContextSetLineJoin(UIGraphicsGetCurrentContext(), kCGLineJoinRound);

It will make a huge difference.

+3
source

OpenGL. touchesMoved, - :

CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());

.

+1

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


All Articles