iOS 区分哪个标注配件被点击

2023-11-27

在我的地图注释中,我有一个 UIButton 作为标注中的每个附件视图。在里面- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control方法,我如何确定触摸了哪个附件视图来处理每个事件?这是我的代码:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];

UIButton *calloutButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIButton *directionsButton = [UIButton buttonWithType:UIButtonTypeCustom];
directionsButton.frame = CGRectMake(0, 0, 23, 23);
[directionsButton setBackgroundImage:[UIImage imageNamed:@"directions.png"] forState:UIControlStateNormal];

MyPin.leftCalloutAccessoryView = directionsButton;
MyPin.rightCalloutAccessoryView = calloutButton;
MyPin.draggable = NO;
MyPin.highlighted = NO;
MyPin.animatesDrop= YES;
MyPin.canShowCallout = YES;
MyPin.pinColor = MKPinAnnotationColorRed;

return MyPin;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

Annotation *ann = view.annotation;

if ([control tag] == 1) {

    CLLocationCoordinate2D currentCoords = {ann.coordinate.latitude, ann.coordinate.longitude};

    MKPlacemark *place = [[MKPlacemark alloc] initWithCoordinate: currentCoords addressDictionary:nil];
    MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark: place];
    destination.name = ann.title;
    destination.url = [NSURL URLWithString:@"http://www.wccca.com/PITS"];
    NSArray *items = [[NSArray alloc] initWithObjects: destination, nil];
    NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                             MKLaunchOptionsDirectionsModeDriving,
                             MKLaunchOptionsDirectionsModeKey, nil];
    [MKMapItem openMapsWithItems: items launchOptions: options];

}

if ([control tag] == 2) {

    MKCoordinateRegion region;
    region.center.latitude = ann.coordinate.latitude;
    region.center.longitude = ann.coordinate.longitude;
    region.span.latitudeDelta  = 0.02;
    region.span.longitudeDelta = 0.02;

    [self.mapView setRegion:region animated:YES];
}

}

您可以只检查是否设置和使用标签control是左或右附件视图:

if (control == view.leftCalloutAccessoryView) {
    //handle left control tap...        
}
else
if (control == view.rightCalloutAccessoryView) {
    //handle right control tap...       
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS 区分哪个标注配件被点击 的相关文章

随机推荐

  • gcc -O2 与无原因错误

    编译包含以下内容的文件时open FILENAME O RDONLY 没有 O2标记一切都很好 但当 O2打开我得到 usr include x86 64 linux gnu bits fcntl2 h In function open u
  • 我如何知道我的 docker mysql 容器何时启动并且 mysql 何时准备好接受查询?

    我正在部署几个不同的 docker 容器 mysql 是第一个 我想在数据库启动后立即运行脚本并继续构建其他容器 该脚本一直失败 因为它试图在设置 mysql 的入口点脚本 来自这个官方的mysql容器 仍在运行 sudo docker r
  • 如何在控制台应用程序中检查 CTRL 键是否被按下#

    我要启动一个控制台应用程序 问题是如何确定CTRL键被单独按下而没有任何其他键 using System using System Text public class ConsoleKeyExample public static void
  • 时间的正则表达式

    我想要 HH MM SS AM PM 的正则表达式 这里 HH 必须是 1 12 MM 必须是 60 分钟 SS 照常 60 秒 我有正确的吗 0 1 9 1 0 2 0 5 0 9 0 5 0 9 59 44 29 60 AM am PM
  • 捆绑包安装使用不同的 Ruby 版本?

    我尝试使用 Knife solo 在 Vagrant 上安装 Ruby 2 0 0 p353 当我以 root 和 vagrant 身份登录时 ruby v返回 Ruby 2 0 0 p353 然而 当我跑步时bundle install在
  • 在运行时在 LINQ 查询中编写 where 子句

    我正在获取一个字符串数组 我想查看域对象中的一定数量的数据字段是否包含所有这些字符串 我知道编译时的数据字段 但不知道编译时数组的大小 有没有一种方法可以让我在运行时编写一个 where 子句 以便我可以在单个 linq 查询中执行我要查找
  • 如何根据字符串的值访问“struct”的成员?

    我想通过使用字符串的值来访问结构中的成员 struct hello world char rate char ssid 有一个变量可以说 char string ssid 我想使用这个字符串的值来引用ssid内的成员hello world结
  • 团队通道上的 botframework 1:1 身份验证 AAD 集成

    我正在寻找在团队频道上连接我的机器人 但我不知道如何确保它仅在我们的域 组织 中使用 我已测试寻找 身份验证 AAD Azure Web App 但它不适用于团队或网络聊天 因为端点地址未重定向 我已经测试了实施 AUTH 卡 但它不适用于
  • Qt:展开〜到主目录

    Qt 是否有任何独立于平台的功能来接受像 myfile 这样的路径 我知道关于wordexp 但是使用独立于平台的包装器会很好 Edit 谢谢大家的回复 myfile 只是一个例子 我正在寻找的是处理文件路径的功能 就像您可以在命令行上编写
  • 如何在 PowerShell 中将 SID 转换为帐户名?

    这个问题的灵感来自于这个类似的问题使用 C 标签 如果我有一个 Windows SID 并且想将其转换为可读的帐户名 如何使用 PowerShell 而不是 C 来实现此目的 现在 我有以下代码 它检索当前登录的用户帐户的组成员身份 Ide
  • Spartan-3E 上的随机数生成

    我需要在 Spartan 3E FPGA 上为我的遗传算法生成伪随机数 并且我想在 verilog 中实现它 您能给我任何关于此的指示吗 当然 Adam 的随机生成器是不可合成的 您必须显式创建一个LFSR 以下示例可能会有所帮助 它是一个
  • 返回 CStringArray 给出错误

    我试图返回一个 CStringArray 在我的 h 中我定义了 Private CStringArray array public CStringArray GetArray 在 我有 CQueue CQueue m hApp 0 m d
  • ASP.NET MVC 多个复选框

    我有一个List我想向用户显示大约 20 个项目 每个项目旁边都有一个复选框 Available我的 ViewModel 上的属性 提交表单时 我希望能够通过以下方法将选中的每个复选框的值传递回我的控制器方法Selections我的 Vie
  • 如何使用 Objective-C 实现 LocalNotification?

    我正在尝试在我的应用程序中实现本地通知 我不知道如何正确执行 下面的代码我用于新的数据到达过程 在如何实现通知过程之后 我在这两个过程中都需要通知foreground and background modes 下面我已经成功backgrou
  • 如何知道导入中可用函数的完整列表有哪些?

    在 Haskell 中 如果我导入一个模块 例如 import Data List 我如何知道 Data List 提供的总方法是什么 在 Prelude 中我可以像这里所说的那样使用完成有没有办法在 GHCI 中查看模块中的函数列表 Pr
  • 我可以使用 Spring Security 拥有多个安全上下文吗?

    我有一个安全上下文定义 它使用 PreAuthenticatedProcessingFilterEntryPoint 作为应用程序的弹性部分 我怎样才能有另一个定义 将标准表单登录与 html 表单用于我的应用程序的另一部分 这是我目前拥有
  • 为什么色情网站会出现在我的 Google Analytics(分析)数据中?

    几天前 我部署了一个网络应用程序 并在其上安装了 Google Analytics 来跟踪活动 几乎每天 我都会至少有一个记录的页面浏览指向 www pornhub forum ga postxxx 或 www youporn forum
  • 获取方法调用者的行号?

    Java中有没有办法获取方法调用者的行号 我不想抛出异常 我必须使用堆栈跟踪吗 有什么方法可以便宜地做到这一点吗 编辑 澄清一下 我不需要调用者班级的行号 我想要调用该方法的确切行 答案是Aasmund提供的作品 但你最好使用 Thread
  • FullCalendar:更改议程日背景颜色

    虽然我看到有人问这个问题 但我还没有看到答案 我只是想能够给它上色background color of the TD从一定范围 假设我的日历每 15 分钟就有一个时段 从上午 9 点到下午 9 点 我只想在上午 10 点到下午 3 点使用
  • iOS 区分哪个标注配件被点击

    在我的地图注释中 我有一个 UIButton 作为标注中的每个附件视图 在里面 void mapView MKMapView mapView annotationView MKAnnotationView view calloutAcces