【发布时间】:2025-12-23 02:35:16
【问题描述】:
如果在 mapView didChangeDragState 中检测到注释被拖到了不需要的位置,我可以在 mapView:didChangeDragState 中取消拖拽。
case .Dragging:
let inColorado = StateOutline.inColorado(view.annotation!.coordinate)
if !inColorado {
view.dragState = .Canceling
}
不幸的是,这会将大头针留在取消拖动的不需要位置的位置。
有人想将注释设置为
- 一个有效的坐标
- 或恢复到拖动前的坐标
-
或设置为拖动的最后一个有效位置
case .Canceling: view.annotation!.coordinate = StateOutline.coloradoCenter() view.dragState = .None }
不允许该坐标设置,因为 view.annotation!.coordinate 是一个 get-only 属性。
如何撤消注释拖动?
不需要考虑使用 MKAnnotation setCoordinate - 它在 iOS 8.3 中被删除。
唯一想到的就是用新的注释替换该注释并在其上设置坐标。理想情况下,引脚坐标将设置为其最后一个有效位置。
【问题讨论】:
标签: ios swift mkannotation mkannotationview