我想在我的应用程序中为建筑楼层实施和设计地图。在开始之前,我想有一些建议。
我打算使用 UIBezierPath 来绘制形状。每个 UIBezierPath 将代表我地图上的一家商店。这是一个插图(map_with_UIBezierPath)
我的代码结构如下:我有一个 UIViewController 和一个 UiView。在 UIViewController "viewDidLoad" 方法中,我实例化了 UIView,在 UIView "drawRect" 方法中,我绘制了如下形状(UIBezierPathExtension 继承自 UIBezierPath):
- (void)drawRect:(CGRect)rect {
context = UIGraphicsGetCurrentContext();
[[UIColor grayColor] setFill];
[[UIColor greenColor] setStroke];
UIBezierPathExtension *aPath = [[UIBezierPathExtension alloc] init];
aPath.pathId = 1;
[aPath moveToPoint:CGPointMake(227,34.25)];
[aPath addLineToPoint:CGPointMake(298.25,34.75)];
[aPath addLineToPoint:CGPointMake(298.5,82.5)];
[aPath addLineToPoint:CGPointMake(251,83)];
[aPath addLineToPoint:CGPointMake(251,67.5)];
[aPath addLineToPoint:CGPointMake(227.25,66.75)];
[aPath closePath];
aPath.lineWidth = 2;
[aPath fill];
[aPath stroke];
[paths addObject:aPath];
UIBezierPathExtension* aPath2 = [[UIBezierPathExtension alloc] init];
aPath2.pathId = 2;
[aPath2 moveToPoint:CGPointMake(251.25,90.5)];
[aPath2 addLineToPoint:CGPointMake(250.75,83.25)];
[aPath2 addLineToPoint:CGPointMake(298.5,83)];
[aPath2 addLineToPoint:CGPointMake(298.5,90.25)];
[aPath2 closePath];
aPath2.lineWidth = 2;
[aPath2 fill];
[aPath2 stroke];
[paths addObject:aPath2];
...
}
我还在 UIViewController 中实现了平移和捏合手势。
现在,我在问我如何与每一个形状进行交互。我想检测一次点击,更改他的颜色并在所选形状上显示类似的菜单。
有人能告诉我正确的方向吗?
提前谢谢