I have a situation where I would like to place a UIView (this is not my code) on top of another UIView and have events that propagate at the bottom of the screen. To be more specific, I would like to place a UIView on top of MKMapView.
I have a UIView that contains both views (like subviews). I would like my uiview to pass events from my view to both of its views.
.h:
@interface MyUIView : UIView
@end
.m:
#import "MyMapView.h"
#import <MapKit/MapKit.h>
#import "MapGestureRecognizer.h"
@implementation MyMapView
MKMapView *mkMapView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
mkMapView = [[MKMapView alloc] initWithFrame:frame];
[self addSubview:mkMapView];
UIView * otherView = [[UIView alloc] initWithFrame:frame];
otherView.backgroundColor = [UIColor clearColor];
[self addSubview:otherView];
MapGestureRecognizer *mgr = [[MapGestureRecognizer alloc] init];
mgr.touchesBeganCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touches began=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);
[mkMapView touchesBegan:touches withEvent:event];
};
mgr.touchesCancelledCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touches cancelled=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);
[mkMapView touchesCancelled:touches withEvent:event];
};
mgr.touchesEndedCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touches ended=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);
[mkMapView touchesEnded:touches withEvent:event];
};
mgr.touchesMovedCallback = ^(NSSet * touches, UIEvent * event) {
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touches moved=%@", [NSString stringWithFormat:@"%i", touch.view.tag]);
[mkMapView touchesMoved:touches withEvent:event];
};
[self addGestureRecognizer:mgr];
return self;
}
@end
I implemented my own gesture recognizer to intercept these events, and I am trying to go to intercepted events through mkMapView. I see log messages, however it does not miss events, since I can scroll / pan mkmapview.