【问题标题】:Why is the viewForAnnotation method messing up my user's location?为什么 viewForAnnotation 方法会弄乱我用户的位置?
【发布时间】:2015-08-31 14:16:05
【问题描述】:

最近我在我的应用程序中实现了 viewForAnnotation 方法来发挥我的注释的特性(图像、颜色等)。唯一的问题是,虽然该功能在我的代码中,但位置服务的行为很奇怪。蓝色位置标记“脉动”并且相对较小,而不是蓝色的整个县阴影,停止脉动,并且相当不稳定。

这是我正在使用的代码:

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

    if annotation is MKUserLocation {

        return nil

    }

    let reuseId = "pin"

    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
    if pinView == nil {
        pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        pinView!.canShowCallout = true
        pinView!.animatesDrop = false
        pinView?.pinColor = .Green
    }
    else {
        pinView!.annotation = annotation
    }

    return pinView

}

此函数中是否存在可能干扰位置服务表示的内容?谢谢。

【问题讨论】:

    标签: ios xcode swift annotations location


    【解决方案1】:

    这行不通:

    if annotation is MKUserLocation {
        return nil
    }
    

    改为:

    if annotation.isMemberOfClass(MKUserLocation.self) {
        return nil
    }
    

    【讨论】:

    • 是的,这行得通。我还没有看到它被使用过,所以我永远不会找到它。谢谢,我会在几分钟内接受你 - 你对系统来说太快了。
    猜你喜欢
    • 2020-08-17
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 2019-04-04
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    相关资源
    最近更新 更多