3

我正在使用下面的代码在 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)

任何帮助表示赞赏。

4

1 回答 1

0

这是这个链接,它可以帮助你。

Monotouch MapKit - 注释 - 向气泡添加按钮

教程-

http://www.altinkonline.nl/tutorials/xcode/corelocation/add-a-button-to-an-annotation/

而不是给按钮类型 roundRect 给它 UIButtonTypeDetailDisclosure

希望对您有所帮助。

于 2013-08-31T05:43:41.203 回答