Actualmente estoy trabajando en un proyecto de iPad donde necesito la funcionalidad para permitir al usuario escribir en un papel con un lápiz.Escritura fluida en iPad
He probado un par de lápices y descubrí que el bambú era el mejor. También tienen una aplicación gratuita que puedes usar para escribir.
El problema al que me enfrento es que el método que uso no ofrece curvas suaves. La aplicación de papel de bambú proporciona líneas de aspecto perfecto. Este es el código que tengo hasta ahora:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsBeginImageContext(self.frame.size);
// draw accumulated lines
if ([self.lines count] > 0) {
for (Line *tempLine in self.lines){
CGContextSetAlpha(context, tempLine.opacity);
CGContextSetStrokeColorWithColor(context, tempLine.lineColor.CGColor);
CGContextSetLineWidth(context, tempLine.lineWidth);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextAddPath(context, tempLine.linePath);
CGContextStrokePath(context);
}
}
//draw current line
CGContextSetAlpha(context, self.currentLine.opacity);
CGContextSetStrokeColorWithColor(context, self.currentLine.lineColor.CGColor);
CGContextSetLineWidth(context, self.currentLine.lineWidth);
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextBeginPath(context);
CGContextAddPath(context, self.currentLine.linePath);
CGContextStrokePath(context);
UIGraphicsEndImageContext();
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint cPoint = [touch locationInView:self];
CGPathMoveToPoint(self.currentLine.linePath, NULL, cPoint.x, cPoint.y);
[self setNeedsDisplay];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
CGPathAddLineToPoint(self.currentLine.linePath, NULL, currentPoint.x, currentPoint.y);
[self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint cPoint = [touch locationInView:self];
CGPathAddLineToPoint(self.currentLine.linePath, NULL, cPoint.x, cPoint.y);
[self setNeedsDisplay];
[self.lines addObject:self.currentLine];
Line *nextLine = [[Line alloc] initWithOptions:self.currentLine.lineWidth color:self.currentLine.lineColor opacity:self.currentLine.opacity];
self.currentLine = nextLine;
[nextLine release];
}
Aquí están las imágenes que dejan en claro qué problema estoy enfrentando. Esta es la imagen de lo que se genera cuando la escritura con el código proporcionado anteriormente:
Esta es la imagen si escribo lo mismo en la aplicación de papel Mamboo:
¿El ¿Alguien tiene una idea de cómo escribir bien en la aplicación mamboo?
posible duplicado de [iPhone algoritmo de dibujo boceto liso] (http://stackoverflow.com/questions/5076622/iphone-smooth-sketch-drawing-algorithm) –
Véase también [cómo puedo rastrear el movimiento de los dedos en el tacto para dibujar curvas suaves?] (http://stackoverflow.com/questions/1052119/how-can-i-trace-the-finger-movement-on-touch-for-drawing-smooth-curves). –
ver muestra https: // github.com/yusenhan/Smooth-Line-View –