Click事件在地图视图中无法正常工作

时间:2013-08-05 11:11:07

标签: iphone objective-c map annotations uibutton

我在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)

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

以下链接可以帮助您。

Monotouch MapKit - annotations - adding a button to bubble

教程 -

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

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

希望帮助你。