Added code to forward touch events to Marker Subclasses if they respond to them
Showing
1 changed file
with
31 additions
and
0 deletions
@@ -234,6 +234,16 @@ | @@ -234,6 +234,16 @@ | ||
234 | 234 | ||
235 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event | 235 | - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event |
236 | { | 236 | { |
237 | + UITouch *touch = [[touches allObjects] objectAtIndex:0]; | ||
238 | + //Check if the touch hit a RMMarker subclass and if so, forward the touch event on | ||
239 | + //so it can be handled there | ||
240 | + id furthestLayerDown = [[[self contents] overlay] hitTest:[touch locationInView:self]]; | ||
241 | + if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) { | ||
242 | + if ([furthestLayerDown respondsToSelector:@selector(touchesBegan:withEvent:)]) { | ||
243 | + [furthestLayerDown performSelector:@selector(touchesBegan:withEvent:) withObject:touches withObject:event]; | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
237 | if (lastGesture.numTouches == 0) | 247 | if (lastGesture.numTouches == 0) |
238 | { | 248 | { |
239 | [RMMapContents setPerformExpensiveOperations:NO]; | 249 | [RMMapContents setPerformExpensiveOperations:NO]; |
@@ -247,6 +257,17 @@ | @@ -247,6 +257,17 @@ | ||
247 | 257 | ||
248 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event | 258 | - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event |
249 | { | 259 | { |
260 | + UITouch *touch = [[touches allObjects] objectAtIndex:0]; | ||
261 | + | ||
262 | + //Check if the touch hit a RMMarker subclass and if so, forward the touch event on | ||
263 | + //so it can be handled there | ||
264 | + id furthestLayerDown = [[[self contents] overlay] hitTest:[touch locationInView:self]]; | ||
265 | + if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) { | ||
266 | + if ([furthestLayerDown respondsToSelector:@selector(touchesCancelled:withEvent:)]) { | ||
267 | + [furthestLayerDown performSelector:@selector(touchesCancelled:withEvent:) withObject:touches withObject:event]; | ||
268 | + } | ||
269 | + } | ||
270 | + | ||
250 | // I don't understand what the difference between this and touchesEnded is. | 271 | // I don't understand what the difference between this and touchesEnded is. |
251 | [self touchesEnded:touches withEvent:event]; | 272 | [self touchesEnded:touches withEvent:event]; |
252 | } | 273 | } |
@@ -254,6 +275,16 @@ | @@ -254,6 +275,16 @@ | ||
254 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event | 275 | - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event |
255 | { | 276 | { |
256 | UITouch *touch = [[touches allObjects] objectAtIndex:0]; | 277 | UITouch *touch = [[touches allObjects] objectAtIndex:0]; |
278 | + | ||
279 | + //Check if the touch hit a RMMarker subclass and if so, forward the touch event on | ||
280 | + //so it can be handled there | ||
281 | + id furthestLayerDown = [[[self contents] overlay] hitTest:[touch locationInView:self]]; | ||
282 | + if ([[furthestLayerDown class]isSubclassOfClass: [RMMarker class]]) { | ||
283 | + if ([furthestLayerDown respondsToSelector:@selector(touchesEnded:withEvent:)]) { | ||
284 | + [furthestLayerDown performSelector:@selector(touchesEnded:withEvent:) withObject:touches withObject:event]; | ||
285 | + } | ||
286 | + } | ||
287 | + | ||
257 | lastGesture = [self getGestureDetails:[event allTouches]]; | 288 | lastGesture = [self getGestureDetails:[event allTouches]]; |
258 | 289 | ||
259 | // NSLog(@"touchesEnded %d ... lastgesture at %f, %f", [[event allTouches] count], lastGesture.center.x, lastGesture.center.y); | 290 | // NSLog(@"touchesEnded %d ... lastgesture at %f, %f", [[event allTouches] count], lastGesture.center.x, lastGesture.center.y); |
-
Please register or login to post a comment