Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to draw and interact with UIBezierPath
    text
    copied!<p>I would like to implement and design a map for a building floor in my application. Before starting, I would like to have some advices.</p> <p>I'm planning to use UIBezierPath to draw the shapes. Each UIBezierPath will represent a shop on my map. Here is an illustration (<a href="http://www.mackiller.be/img/map_with_UIBezierPath.png" rel="nofollow">map_with_UIBezierPath</a>)</p> <p>My code structure is the following: I have a UIViewController And a UiView. In the UIViewController "viewDidLoad" method, I instantiate the UIView and in the UIView "drawRect" method, I draw the shapes like following (UIBezierPathExtension inherit from UIBezierPath):</p> <pre><code>- (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]; ... } </code></pre> <p>I have also implemented the pan and pinch gesture in the UIViewController.</p> <p>Now, I'm asking me how I can interact with every single shapes. I would like to detect a single tap on it, change his color and display a menu like <a href="http://www.mackiller.be/img/shop_selected.png" rel="nofollow">that</a> on the selected shape.</p> <p>Can someone tell me the right direction to take?</p> <p>Thx in advance</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload