Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 只画直线,不画平滑线_Iphone_Objective C_Ios_Draw - Fatal编程技术网

Iphone 只画直线,不画平滑线

Iphone 只画直线,不画平滑线,iphone,objective-c,ios,draw,Iphone,Objective C,Ios,Draw,} 我正在用这个代码画线。但我希望这条线保持直线。这意味着当我移动我的触摸时,线条不应变得平滑。线条将保持笔直 我想我必须做一些类似的事情 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:scrollV

}

我正在用这个代码画线。但我希望这条线保持直线。这意味着当我移动我的触摸时,线条不应变得平滑。线条将保持笔直

我想我必须做一些类似的事情

 -(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
如果移动子像素,将得到不需要的抗锯齿效果。我建议地板/天花板为非浮式。与非视网膜相比,使用视网膜时,这显然变得更复杂。

实际上,我必须限制触摸,这意味着如果我使用垂直或水平触摸,我必须根据它设置点。我不能从这个答案中得到答案,但这有助于我更详细地理解它。
  if (currentPoint.x > lastPoint.x){        
    currentPoint.y = lastPoint.y;
} 
else if (currentPoint.x < lastPoint.x) {
    currentPoint.x = lastPoint.x;
}