-(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)
如果您要移动子像素,您将获得不需要的抗锯齿。我建议地板/ ceil到非浮动。当使用视网膜与非视网膜时,这显然变得更加复杂。