我正在使用下面的代码在 mapView 中添加按钮,但按钮单击事件仅在左侧大小上起作用,而在右侧不起作用。
MKPinAnnotationView *pinAnnotation = nil;
if(annotation != beerMapView.userLocation)
{
static NSString *defaultPinID = @"myPin";
pinAnnotation.pinColor = MKPinAnnotationColorRed;
pinAnnotation = (MKPinAnnotationView *)[beerMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinAnnotation == nil )
pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
NSLog(@"PinAnnotation: %@",NSStringFromCGRect(pinAnnotation.frame));
pinAnnotation.canShowCallout = YES;
pinAnnotation.image = [UIImage imageNamed:@""]; //Set blank pin image
UIImageView *pinImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
pinImage.image = [UIImage imageNamed:@"ic_pin.png"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[infoButton setImage:[UIImage imageNamed:@"ic_pin.png"] forState:UIControlStateNormal];
infoButton.frame = CGRectMake(0, 0, 40, 40);
pinAnnotation.rightCalloutAccessoryView = infoButton;
[infoButton addTarget:self action:@selector(detailBtnClk:) forControlEvents:UIControlEventTouchUpInside];
[pinAnnotation addSubview:infoButton];
}
infoButton - > 左侧部分(0 到 20)按钮单击事件工作。(调用 detailBtnClk)
infoButton -> 右侧部分(21 到 40)按钮单击事件不起作用。(不能调用detailBtnClk)
任何帮助表示赞赏。