4

こんにちは、私はフランス人ですので、英語を教えてください。私の問題は、iPhoneで指でそのような点線の描画を描きたいということです----------、線ではなく描画です。

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); // for size
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

「点線」のコードを教えてください。

4

3 に答える 3

4

CGContextSetLineDash

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html%23//apple_ref/c/func/CGContextSetLineDash

例:

CGFloat dashes[] = { 1, 1 };
CGContextSetLineDash( context, 0.0, dashes, 2 );

または、Xcode で QuartzDemo サンプルを開き、QuartzLines.m ファイル (QuartzDashView クラス) を確認します。

本当にドキュメントを読む必要があります(すでに言及されたリンクを参照してください)。

于 2011-02-19T18:05:14.177 に答える
2

あなたの問題は、これを行う前にコンテキストを参照しなかったことです: CGContextSetLineDash( context, 0.0, dashes, 2 );

これを行う必要があります:CGContextRef context = UIGraphicsGetCurrentContext();次に、すべての UIGraphicsGetC... 呼び出しをコンテキストに置き換えて、とにかく高速化します。

Deitel の iPhone App-Driven Approach book には、これを行う例があります。

ファイティングS

于 2011-03-14T05:12:35.463 に答える
0

ラインプロパティの役割についての素晴らしいページを参照してください! https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/

上記のページによると、「ドット」行のコードは次のとおりです ( . . . .)

// should
CGContextSetLineCap(context, kCGLineCapRound);

// please see the role of line properties why the first should be 0 and the second should be the doulbe of the given line width
CGFloat dash[] = {0, lineWidth*2};

// the second value (0) means the span between sets of dot patterns defined by dash array
CGContextSetLineDash(context, 0, dash, 2);
于 2016-09-01T02:53:05.613 に答える