Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone:连接到形状的线路连接器_Iphone_Core Graphics_Shapes_Bezier_Connector - Fatal编程技术网

iPhone:连接到形状的线路连接器

iPhone:连接到形状的线路连接器,iphone,core-graphics,shapes,bezier,connector,Iphone,Core Graphics,Shapes,Bezier,Connector,如何在两个形状之间绘制线条连接线,使线条以适当的角度绘制,并随着形状的任何移动而移动 大概是这样的: 我想我需要的是一条UIBezier曲线,但任何入门教程或帮助都将不胜感激。我认为这是正确的方法,所以你一定要仔细阅读。我写了一个创建路径的快速示例,我没有使用更多的选项 绘制路径不是困难的部分。您必须跟踪您创建的所有框,并以某种方式存储它们之间的连接,这在很大程度上取决于您存储框的方式,但关系数据库感觉是正确的解决方案。给定这些对象和连接,您将在drawrect中为其中一个视图生成路径 - (v

如何在两个形状之间绘制线条连接线,使线条以适当的角度绘制,并随着形状的任何移动而移动

大概是这样的:

我想我需要的是一条UIBezier曲线,但任何入门教程或帮助都将不胜感激。

我认为这是正确的方法,所以你一定要仔细阅读。我写了一个创建路径的快速示例,我没有使用更多的选项

绘制路径不是困难的部分。您必须跟踪您创建的所有框,并以某种方式存储它们之间的连接,这在很大程度上取决于您存储框的方式,但关系数据库感觉是正确的解决方案。给定这些对象和连接,您将在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上的许多其他方法来弯曲线条。大多数路径都取决于你的风格,没有一种正确的风格来连接两点。

你有没有一个逻辑来连接它们——什么时候画直线,什么时候画90度直线?没有。还没走多远。我接受这个答案。寻找一个好的代码示例。谢谢