我正在使用下面的代码在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)
任何帮助表示赞赏。
最佳答案
这是对您有帮助的链接。
Monotouch MapKit - annotations - adding a button to bubble
教程-
http://www.altinkonline.nl/tutorials/xcode/corelocation/add-a-button-to-an-annotation/
而不是给按钮类型roundRect,而是给它UIButtonTypeDetailDisclosure
希望对您有所帮助。
关于iphone - 点击事件在 map View 中无法正常运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18056748/