gpt4 book ai didi

ios - 在 Objective-C 中发布带有两个端点的绘图线

转载 作者:行者123 更新时间:2023-11-29 02:48:22 25 4
gpt4 key购买 nike

我正在尝试绘制一条线,每条线的两端都有一个圆点,并将其作为图层添加到 View 中。我已经记下了一般概念,但正如您从屏幕截图中看到的那样,这条线有点错位,我一直无法弄清楚原因。

enter image description here

我也不确定为什么那里有一条线开始(如您所见,我已经注释掉了应该用来画线的两条线,但线还是画了)。

//Draw circle
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];

//Add second circle
[path addArcWithCenter:CGPointMake(200.0, 200.0) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];
//[path addLineToPoint:CGPointMake(200.0, 200.0)];
//[path moveToPoint:CGPointMake(200.0, 200.0)];

[path closePath];
[[UIColor redColor] setStroke];
[[UIColor redColor] setFill];
[path stroke];
[path fill];

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [[UIColor redColor] CGColor];
shapeLayer.lineWidth = 4.0;
shapeLayer.fillColor = [[UIColor redColor] CGColor];

[self.view.layer addSublayer:shapeLayer];

感谢任何帮助!

最佳答案

UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 100) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];     

//Add second circle
[path moveToPoint:CGPointMake(100.0, 100.0)];
[path addLineToPoint:CGPointMake(200, 200)];
[path moveToPoint:CGPointMake(200, 200)];

[path addArcWithCenter:CGPointMake(200, 200) radius:10 startAngle:0 endAngle:DEGREES_TO_RADIANS(360) clockwise:TRUE];

关于ios - 在 Objective-C 中发布带有两个端点的绘图线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24838416/

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