Obecnie pracuję nad projektem na iPada, w którym potrzebuję funkcji pozwalającej użytkownikowi pisać na kartce papieru za pomocą rysika.Płynne pisanie na iPadzie
Przetestowałem kilka rysików i odkryłem, że bambus jest najlepszy. Mają też darmową aplikację, której możesz użyć do napisania.
Problem, który napotykam, polega na tym, że metoda, której używam, nie zapewnia płynnych krzywych. Bambusowa aplikacja na papier zapewnia idealnie wyglądające linie. To jest kod, który mam do tej pory:
- (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];
}
Oto obrazy, które jasno pokazują, jaki problem mam do czynienia. Jest to obraz tego, co zostanie wygenerowany podczas pisania kodu podany powyżej:
To jest obraz, czy piszę to samo w aplikacji mamboo papieru:
Does Czy ktoś ma pomysł, jak uzyskać ładne pisanie, jak w aplikacji mamboo?
możliwy duplikat [algorytmu rysowania gładzi iPhone'a] (http://stackoverflow.com/questions/5076622/iphone-smooth-sketch-sketch-drawing-algorithm) –
Zobacz także [jak mogę śledzić ruch palca na dotyku do rysowania gładkich krzywych?] (http://stackoverflow.com/questions/1052119/how-can-i-trace-the-finger-movement-on-touch-for-drawing-beooth-curves). –
zobacz przykładowy https: // github.com/yusenhan/Smooth-Line-View –