0
免費抽獎手寫的最佳方式
可能重複:
how to create an application which allows user to free hand drawing?什麼是提供IOS
我想實現在視圖上自由手寫。我使用了一些現有的代碼,當用戶寫入速度非常慢時,這種代碼運行良好,就好像用戶寫得非常快,並不能識別所有點(用戶觸及的點)。 我的示例代碼是在這裏
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.bounds.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
if (mode == DrawingModePen) {
NSLog(@"drawing");
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [_drawingPenColor CGColor]);
}
else {
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), [[UIColor clearColor] CGColor]);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextClearRect (UIGraphicsGetCurrentContext(), CGRectMake(lastPoint.x, lastPoint.y, 20, 20));
CGContextStrokePath(UIGraphicsGetCurrentContext());
NSLog(@"clearing");
}
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
是否有任何其他方式來實現這個?我見過由蘋果提供的GLPaint。它在我的應用程序中引起的內存警告也沒有多大用處。
感謝您的回覆,我只需要徒手繪畫,無論您提供的鏈接是什麼,這在某種程度上是有幫助的,我會嘗試使用它。 – ajay