Ios 如何在两点之间画一条线目标C
尝试在两个点ImageView之间绘制直线时,会在另一个位置生成该直线 这是我的代码: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
- (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];
}