为什么 viewForAnnotation 方法弄乱了我的用户位置?
Why is the viewForAnnotation method messing up my user's location?
最近我在我的应用程序中实现了 viewForAnnotation 方法来玩转我的注释的特征(图像、颜色等)。唯一的问题是,虽然该功能在我的代码中,但定位服务的行为很奇怪。它不是蓝色位置标记 "pulsing" 并且相对较小,而是将整个县变成蓝色,停止脉动,并且相当不稳定。
这是我使用的代码:
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
}
此函数中是否有可能干扰位置服务表示的内容?谢谢。
这行不通:
if annotation is MKUserLocation {
return nil
}
改为使用:
if annotation.isMemberOfClass(MKUserLocation.self) {
return nil
}
最近我在我的应用程序中实现了 viewForAnnotation 方法来玩转我的注释的特征(图像、颜色等)。唯一的问题是,虽然该功能在我的代码中,但定位服务的行为很奇怪。它不是蓝色位置标记 "pulsing" 并且相对较小,而是将整个县变成蓝色,停止脉动,并且相当不稳定。
这是我使用的代码:
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
}
此函数中是否有可能干扰位置服务表示的内容?谢谢。
这行不通:
if annotation is MKUserLocation {
return nil
}
改为使用:
if annotation.isMemberOfClass(MKUserLocation.self) {
return nil
}