2012-02-08 7 views
0
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
mouseSwiped = YES; 

UITouch *touch = [touches anyObject]; 
CGPoint currentPoint = [touch locationInView:scrollView]; 

//[self drawLine:lastPoint.x :lastPoint.y :currentPoint.x :currentPoint.y]; 
tempShapeLayer = nil; 
CGMutablePathRef linePath = nil; 
linePath = CGPathCreateMutable(); 
tempShapeLayer = [CAShapeLayer layer]; 

tempShapeLayer.lineWidth = 4.0f; 
tempShapeLayer.lineCap = kCALineJoinMiter; 
tempShapeLayer.strokeColor = [[UIColor redColor] CGColor]; 


CGPathMoveToPoint(linePath, NULL, lastPoint.x, lastPoint.y); 
CGPathAddLineToPoint(linePath, NULL, currentPoint.x, currentPoint.y); 


tempShapeLayer.path = linePath; 
CGPathRelease(linePath); 

[scrollView.layer addSublayer:tempShapeLayer]; 

lastPoint = currentPoint; 

}だけ直線を引く私はこのコードで線を引いています

を滑らかではありません。しかし、私はこの線を真っ直ぐにしておきたい。私が私のタッチを動かすとラインがスムーズにならないことを意味します。ラインは真っ直ぐに留まります。

は、私は、あなたが不要なアンチエイリアスを取得するサブピクセルを移動する場合

if (currentPoint.x > lastPoint.x){   
    currentPoint.y = lastPoint.y; 
} 
else if (currentPoint.x < lastPoint.x) { 
    currentPoint.x = lastPoint.x; 
} 

答えて

0

ような何かをしなければならないと思います。私はフロア/セイルを非フロートにすることをお勧めします。これは、明らかに、網膜対網膜で作業するときにはより複雑になる。

+0

実際に私はタッチを制限しなければならない、つまり、もし私が縦または横のタッチになったら、それに応じてポイントを設定しなければならないということを意味する。 – PJR

+0

私はこの答えによって答えを得ることはありませんが、それをより詳細に理解するのに役立ちます。 – PJR

関連する問題