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;
}
實際上,我必須限制觸摸,意味着如果我在縱向或橫向觸摸,我必須根據它設置點。 – PJR 2012-02-08 06:48:22
我沒有得到這個答案的答案,但它有助於我更詳細地瞭解它。 – PJR 2012-05-22 08:51:02