Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Ios 如何在两点之间画一条线目标C_Ios_Objective C - Fatal编程技术网

Ios 如何在两点之间画一条线目标C

Ios 如何在两点之间画一条线目标C,ios,objective-c,Ios,Objective C,尝试在两个点ImageView之间绘制直线时,会在另一个位置生成该直线 这是我的代码: - (void)drawLine:(UIView*)currentPoint endPoint:(UIImageView*)lastPoint{ UIBezierPath* path = [UIBezierPath bezierPath]; [path moveToPoint:currentPoint.center]; [path addLineToPoint:lastPoint.c

尝试在两个点ImageView之间绘制直线时,会在另一个位置生成该直线

这是我的代码:

- (void)drawLine:(UIView*)currentPoint endPoint:(UIImageView*)lastPoint{

    UIBezierPath* path = [UIBezierPath bezierPath];
    [path moveToPoint:currentPoint.center];
    [path addLineToPoint:lastPoint.center];


    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [path CGPath];
    shapeLayer.strokeColor = [[UIColor whiteColor] CGColor];
    shapeLayer.lineWidth = 1.0;
    [self.DrawView.layer addSublayer:shapeLayer];

}

看起来你需要给你的收银机一个框架

shapeLayer.frame=CGRectMake0,01000

类似这样的内容请确保您的currentPoint和lastPoint位于self.DrawView中

您可以在currentPoint.superview.layer中添加线,如下所示


一切看起来都很好。您能分享/检查您传递给绘图线功能的CGPoints值吗
- (void)drawLine: (UIView*)currentPoint endPoint:(UIImageView*)lastPoint{
    UIBezierPath* path = [UIBezierPath bezierPath];
    [path moveToPoint:currentPoint.center];
    [path addLineToPoint:lastPoint.center];

    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = [path CGPath];
    shapeLayer.strokeColor = [[UIColor whiteColor] CGColor];
    shapeLayer.lineWidth = 1.0;
    [currentPoint.superview.layer addSublayer:shapeLayer];
}