简体   繁体   English

ios mapview。 取消标注,但保持注释处于选中状态

[英]ios mapview. Dismiss callout but keep annotation selected

I've got a situation where I have some custom annotations on mapview. 我遇到了在mapview上有一些自定义注释的情况。 When these annotations are selected I change the image to a selected state via the 选择这些注释后,我会通过将该图像更改为选定状态

didSelectAnnotationView 

method with a call to [view setImage] and I also show a callout bubble. 调用[view setImage]的方法,并且还显示了一个标注气泡。 The callout has an accessory view that adds a new subview with more information in it when tapped. 标注具有一个附件视图,在点击该附件时会添加一个新子视图,并在其中包含更多信息。 All this works fine, except that when I tap the callout accessory view I want the callout to disappear, but the selected image state to remain. 所有这些都工作正常,除了当我点击标注附件视图时,我希望标注消失,但所选图像状态保持不变。 Currently the only way I know how to dismiss the callout is via 目前,我唯一知道如何取消标注的方法是通过

 didDeselectAnnotationView

however this is also where I would set the image state to be the default unselected image. 但是,这也是我将图像状态设置为默认未选择图像的地方。

Does anyone know if it is possible to dismiss the callout only but retain the selected state on my annotation? 有谁知道是否可以仅取消标注但保留注释中的选定状态?

I've sort of got this working by setting a boolean when the detailView has been added to decide whether or not to remove the "active" image. 我已经通过在添加detailView时设置布尔值来决定是否删除“活动”图像,从而实现了这一目的。 However it becomes tricky when I select a new annotation as I end up with multiple annotations showing the selected state image. 但是,当我选择一个新注释时会变得很棘手,因为我最终会看到显示所选状态图像的多个注释。 I've tried looping through all annotations and setting their image to the "off" state but this doesn't seem to work and I've tried setting a reference to the currently selected annotation and changing the image on that, but again it hasn't worked. 我尝试遍历所有注释并将它们的图像设置为“关闭”状态,但这似乎不起作用,并且我尝试设置对当前所选注释的引用并在其上更改图像,但是再次没有没有工作。

Example flow: 流程示例:

  • User selects a pin 用户选择一个图钉
  • didSelectAnnotationView is called didSelectAnnotationView被称为
  • Pin image changes to "active" and callout is shown 固定图片变为“活动”并显示标注
  • User taps accessory view in callout. 用户在标注中点击附件视图。
  • BOOLEAN popOverShowing is set to YES BOOLEAN popOverShowing设置为YES
  • didDeselectAnnotationView is called. didDeselectAnnotationView被调用。 As popOverShowing is YES the image is not changed to off state but callout disappears 当popOverShowing为YES时,图像未更改为关闭状态,但标注消失了
  • User taps New annotation 用户点击新注释
  • Popover disappears and popOverShowing set to NO 弹出窗口消失并且popOverShowing设置为NO
  • New annotation is set to "active" image 新注释设置为“有效”图像
  • all other annotations should get reset to off image (this is what doesn't seem to happen) 所有其他注释重置为关闭图像(这似乎没有发生)

Keep the reference of previousPin set it off in didSelectAnnotationView unless is nil. 除非为nil,否则请在didSelectAnnotationView中将previousPin的引用设置为关闭。 Then set the new selected pin as previousPin. 然后将新选择的引脚设置为previousPin。 Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM