我有一个UIScrollView
(灰色),上面有一个UIView
(白色)。在视图中,我在MKMapView
里面附上了一个带有别针的。
由于某些未知原因,该引脚在点击时不显示弹出窗口。这里有一些代码:
UIView * whiteMapView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];
whiteMapView.backgroundColor = [UIColor whiteColor];
whiteMapView.clipsToBounds = NO;
whiteMapView.userInteractionEnabled = YES;
[self.scrollView addSubview:whiteMapView];
x = 10.0f;
y = x;
w = CGRectGetWidth(whiteMapView.frame) - (x * 2);
h = w;
self.mapView = [[MKMapView alloc] initWithFrame:CGRectMake(x, y, w, h)];
self.mapView.delegate = self;
self.mapView.scrollEnabled = NO;
[whiteMapView addSubview:self.mapView];
[self.mapView removeAnnotations:self.mapView.annotations];
Shop * shop = [[Shop alloc] init];
shop.name = self.userInfo[@"shopName"];
shop.shopDescription = self.userInfo[@"goods_description"];
shop.latitude = self.userInfo[@"lat"];
shop.longitude = self.userInfo[@"lon"];
MapPin * pin = [[MapPin alloc] initWithShop:shop];
[self.mapView addAnnotation:pin];
这里的委托方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation
{
if (annotation == mapView.userLocation)
{
return nil;
}
else
{
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
pinView.userInteractionEnabled = YES;
pinView.image = [UIImage imageNamed:@"pin_mappa_red"];
pinView.canShowCallout = YES;
pinView.animatesDrop = NO;
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
disclosureButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
disclosureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[disclosureButton addTarget:self action:@selector(didPressPin:) forControlEvents:UIControlEventTouchUpInside];
disclosureButton.tag = [[[(MapPin *)annotation shop] idshop] intValue];
pinView.rightCalloutAccessoryView = disclosureButton;
return pinView;
}
}
在应用程序的另一部分,此代码完美运行。
想法?