2012-02-08 80 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