gpt4 book ai didi

ios - 如何在两点之间画一条线 objective-C

转载 作者:行者123 更新时间:2023-11-28 23:28:23 25 4
gpt4 key购买 nike

当试图在两点(imageViews)之间画一条线时,这条线是在另一个位置生成的。

enter image description here

这是我的代码:

- (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];

}

最佳答案

请确保您的currentPointlastPoint位于self.DrawView中。

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

- (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];
}

关于ios - 如何在两点之间画一条线 objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57815666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com