【问题标题】:User location update with MKPinAnnotationView and MKAnnotationView使用 MKPinAnnotationView 和 MKAnnotationView 更新用户位置
【发布时间】:2015-01-24 02:51:50
【问题描述】:

知道为什么会出现以下情况:

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
    pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
    pinView!.annotation = annotation
    pinView!.canShowCallout = false
    pinView!.draggable = true

允许可拖动的注释在以下情况下快速回到用户位置:

    let reuseId = "pin"
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
    pinView!.annotation = annotation
    pinView!.canShowCallout = false
    pinView!.draggable = true

不回弹到用户位置。

这是在 viewForAnnotation 函数中实现的,它允许您更改当前位置图钉。

我正在尝试编辑用户位置的图钉,我希望它可以拖动,但我希望它在完成拖动后快速回到用户位置。它只在 MKPinAnnotationView 中执行,但我需要它为 MKAnnotatioView 工作。感谢您的帮助!

【问题讨论】:

    标签: ios swift mkmapview


    【解决方案1】:

    不幸的是,我认为这就是子类的实现方式。

    我认为解决方法是使用类似的东西:

    - (void)mapView:(MKMapView *)mapView 
            annotationView:(MKAnnotationView *)annotationView 
            didChangeDragState:(MKAnnotationViewDragState)newState 
            fromOldState:(MKAnnotationViewDragState)oldState 
    {
        if (newState == MKAnnotationViewDragStateEnding)
        {
            //reset CLLocationCoordinate2D of MKAnnotation to the old coordinate (i.e. where the annotation view was before dragging)
        }
    }
    

    请注意,我认为要刷新注释,您可能必须删除注释并将其重新添加。管脚更容易管理,但我知道它们不容易定制。

    【讨论】:

    • 啊,这是最有意义的!非常感谢!
    • 当然!如果您需要任何其他帮助,请告诉我。你也能接受答案吗:) :)
    猜你喜欢
    • 2012-05-16
    • 2023-03-15
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多