gpt4 book ai didi

ios - 允许在没有标注附件 View 的情况下点击注释标注上的任意位置

转载 作者:IT王子 更新时间:2023-10-29 08:07:53 24 4
gpt4 key购买 nike

我有一个 map View ,它或多或少像这样添加注释:

- (MKAnnotationView *)mapView:(MKMapView *)mapView
viewForAnnotation:(id <MKAnnotation>) annotation
{
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"MKPinAnnotationView"];
annotationView.canShowCallout = YES;

UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[detailButton addTarget:self
action:@selector(handleButtonAction)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = detailButton;

return annotationView;
}

在 iOS 7 中,这会在标注的右侧放置一个“i”图标。点击图标触发 mapView:annotationView:calloutAccessoryControlTapped:(在委托(delegate)上)和 handleButtonAction:(在自身上)。不过,我最近意识到,您还可以点击标注上的其他任何位置,并触发相同的两种方法。

这种情况发生在 UIButtonTypeDetailDisclosure 类型的按钮上,但它似乎不会发生在 UIButtonTypeCustom 按钮上。当我在根本没有附件 View 的情况下点击标注时,委托(delegate)方法也不会被触发。 (当然,这种行为并不令人惊讶;令人惊讶的是,如果附件 View 是一个细节披露按钮,那么无论您是点击按钮本身还是点击某个地方,这两个方法都会被触发其他在标注中。)

我想去掉标注中的按钮——或者至少用一个显示我自己的图像的按钮代替它,而不是常用的“i”图标——同时仍然允许用户点击标注上的任意位置触发我的行动。这可能吗?我没有看到对应于“callout tapped”的 MKMapViewDelegate 方法。

最佳答案

尝试在不更改 UIButtonTypeDetailDisclosure 类型的情况下为按钮设置自定义图像。

UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];        
[detailButton setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];

对于 iOS7 及更高版本,此图像将默认着色。如果您想保留原始图标,请使用以下内容

[[UIImage imageNamed:@"icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

或者如果你想完全删除图标

[detailButton setImage:[UIImage new] forState:UIControlStateNormal];

关于ios - 允许在没有标注附件 View 的情况下点击注释标注上的任意位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22133034/

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