Creating a view with an MKMapView and a touchable subview
Is it possible to create a view with both an MKMapview and another subview. In particular I have a map view and I have been trying to add a second subview (to the superview, not the MKMapView.) The problem is that while both view can be seen any touches to the UIView that is not the MKMapView pass through to the map. I even tried to move the map so that they do not overlap but the other UIView locates itself relative to the map, not the window.
An additional curiosity is that the code works fine on the simulator, but not on a test device that is running 3.1.3. Could this be a problem with the 3.1.3 version of MKMapView or just a quirk in the simulator?
My code is
combinedView = [[UIView alloc] initWithFrame:self.view.frame];
self.awView = [[AdWhirlView alloc] init];
awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
self.awView.delegate = self;
[combinedView addSubview:awView];
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,50,320,430)];
mapView = (MKMapView*)self.view;
mapView.delegate = self;
//[self.view insertSubview:mapView atIndex:0];
[combinedView addSubview:mapView];
//mapView.showsUserLocation = YES;
// Create a location coordinate object
CLLocationCoordinate2D coordinate;
coordinate.latitude = 40.1;
coordinate.longitude = -76.30575;
// Display map
mapView.region = MKCoordinateRegionMakeWithDistance(coordinate, 40000, 40000);
[combinedView bringSubviewToFront:awView开发者_运维百科];
Thanks for any advice.
Not too familiar with AdWhirlView, but is it possible you need to set a frame for that as well? CGRectMake(0,0,320,50);
or something?
Otherwise, you might want to play with the autoresizeMasks of the two views. I know for certain you can have a MKMapView with sibling views, and they all work fine.
精彩评论