如何在两个形状之间绘制线连接器,以便该线以适当的角度绘制并随着形状的任何移动一起移动?iPhone:连接到形状的线连接器
事情是这样的:
我想象UIBezier曲线正是我需要的,但任何教程或入门,将不胜感激帮助。
如何在两个形状之间绘制线连接器,以便该线以适当的角度绘制并随着形状的任何移动一起移动?iPhone:连接到形状的线连接器
事情是这样的:
我想象UIBezier曲线正是我需要的,但任何教程或入门,将不胜感激帮助。
我认为UIBezierPath是正确的路要走,所以你一定要阅读它。我写了一个快速示例,让我有更多的选择,我不使用。
绘制路径不是困难的部分。 你必须跟踪你创建的所有框,并在它们之间存储它们之间的连接。不知何故,它很大程度上取决于你如何存储框,但关系数据库感觉是正确的解决方案。鉴于这些对象和连接,您将为您的某个视图生成正确的路径。
- (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其他方法。大部分路径的东西取决于你的风格,没有一个正确的风格来连接两个点。
我会接受这个答案。寻找一个很好的代码示例。谢谢! – Jordan 2012-11-25 19:33:06
你是否得到了连接它们的逻辑 - 什么时候绘制一条直线,何时绘制一个90度的直线? – Prathiba 2012-07-12 06:22:31
号还没有得到很远。 – Jordan 2012-07-17 03:24:57