рисовать только прямую линию не гладко - PullRequest
0 голосов
/ 08 февраля 2012
 -(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;
}

1 Ответ

0 голосов
/ 08 февраля 2012

если вы перемещаете субпиксели, вы получите нежелательное сглаживание. Я предлагаю пол / потолок не плавать. Это, очевидно, усложняется при работе с сетчаткой и без сетчатки.

...