2012-02-08 79 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 2012-02-08 06:48:22

+0

我沒有得到這個答案的答案,但它有助於我更詳細地瞭解它。 – PJR 2012-05-22 08:51:02