gpt4 book ai didi

iphone - 单击事件在 map View 中无法正常工作

转载 作者:行者123 更新时间:2023-12-03 20:14:17 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com