您将如何在两个形状之间绘制线条连接器,以便线条以适当的角度绘制并随着形状的任何移动而移动?
像这样的东西:
我想 UIBezier 曲线是我需要的,但任何教程或入门帮助将不胜感激。
您将如何在两个形状之间绘制线条连接器,以便线条以适当的角度绘制并随着形状的任何移动而移动?
像这样的东西:
我想 UIBezier 曲线是我需要的,但任何教程或入门帮助将不胜感激。
我认为UIBezierPath是正确的方法,所以你绝对应该阅读它。我写了一个快速示例来制作路径,还有很多我没有使用的选项。
绘制路径并不是困难的部分。您必须跟踪您创建的所有盒子并以某种方式存储它们之间的连接,这在很大程度上取决于您存储盒子的方式,但关系数据库感觉像是正确的解决方案。给定这些对象和连接,您将在 drawrect 中为您的一个视图生成路径。
- (void)drawRect:(CGRect)rect {
// say we already created a "Make" box
UIBoxThing *make = ...
// and here we already created a "Diagrams" box
UIBoxThing *diagrams = ...
[[UIColor blackColor] setStroke];
// since we know Diagrams and Make are connected (via some other data), we must draw an arrow between them
UIBezierPath *path = [[UIBezierPath alloc] init];
path.lineWidth = 2;
// the midpoint of the right side of our first box
CGPoint start = CGPointMake(make.frame.origin.x+make.frame.size.width, make.frame.origin.y+(make.frame.size.height/2));
[path moveToPoint:start];
// the midpoint of the left size of our second box
CGPoint end = CGPointMake(diagram.frame.origin.x, diagram.frame.origin.y+(diagram.frame.size.height/2));
[path addLineToPoint:end];
[path stroke];
}
这将与可以判断框是在彼此右侧还是左侧的代码相辅相成,并且您可以使用 addCurveToPoint: 或 UIBezierPath 上的许多其他方法弯曲线。大多数路径的东西取决于你的风格,没有一种正确的风格可以连接两个点。