如何在iOS中用一条线连接两个按钮(点)? [英] How to connect two buttons( dots) with a line in iOS?
问题描述
我要创建一个项目,在该项目中,我必须触摸一个点并将其与另一个点连接,然后再将其连接到另一个点.当我将一个点与另一个点连接在一起时,线将在它们之间创建.
I want to make a project in which I have to touch one dot and connect it with another dot and after connect it to another dot. When I connect one dot with another dot the line will create between them.
实际上,当我单击/触摸一个点时,将显示该线,而当我单击第二个点时,将在两个点之间创建该线.
Actually when I click/ touch one dot The line will show and When I touch second dot the line will create between the two dots.
我还无法执行此操作,我正在尝试并在网上搜索,但仍无法找到解决方案.
I am not able to do this yet, I am trying and searching on the net but unable to find the solution yet.
这是我的需要像这样的 https ://play.google.com/store/apps/details?id = zok.android.dots& hl = zh_CN
This is my need Like this one https://play.google.com/store/apps/details?id=zok.android.dots&hl=en
我认为这是由UIGesture Recogniser完成的吗?还是这其他?我该如何实现?
I think this is done by UIGesture Recogniser? Or is this something else? How I can achieve this?
任何想法或专家的建议都将受到欢迎.
Any Idea or suggestions from experts would be highly welcome.
推荐答案
根据您的要求修改此代码
Modify this code according to your requiements
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *currentColor = [UIColor blackColor];
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);
CGContextSetLineWidth(context, 2.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, touchStart.x, touchStart.y);
CGContextAddLineToPoint(context, touchEnd.x, touchEnd.y);
CGContextStrokePath(context);
@Nisha:
制作CGPoint
touchStart
和touchEnd
的角点实例,并像这样获得它们:
Make gloabal instances of CGPoint
touchStart
and touchEnd
and get them like this:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
touchEnd = CGPointZero;
touchStart = CGPointZero;
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
NSLog(@"start point >> %@",NSStringFromCGPoint(point));
touchStart = point;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
touchEnd = point;
[self setNeedsDisplay];
}
这篇关于如何在iOS中用一条线连接两个按钮(点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!