3

iPhoneで指のスライド/タッチモーションで滑らかな線を描くにはどうすればよいですか? 次のコードがありますが、スムーズではありません。たとえば、円を作ろうとすると、コーナー/ターンが発生します。OpenGLを使用する必要があると思います。何か案は?サンプルコード?チュートリアル?

ありがとう!

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();
4

3 に答える 3

5

最終的に Open GL とパーティクルを使用しました。これを確認するための良い例は、Apple の GLPaint サンプル コードです。

于 2010-04-22T21:54:21.407 に答える
3

これをコードに追加して、ポイント間の線を滑らかにします

CGContextSetLineJoin(UIGraphicsGetCurrentContext(), kCGLineJoinRound);

それは大きな違いを生むでしょう

于 2010-10-19T10:36:19.523 に答える
1

OpenGL は必要ありません。開始点への参照を保持し、コンテキストをクリアしてtouchesMoved、次の行に沿って何かを行うだけです。

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

これにより、開始点から現在の点まで直線が作成されます。

于 2010-04-21T06:35:38.917 に答える