在Swift

时间:2019-01-15 23:06:13

标签: ios mapkit mkannotationview

除了用于用户位置的闪烁的蓝点外,我还要在用户的位置显示用户的图片。是否可以显示注释视图以及闪烁的蓝点?或者,可以简单地创建一个图像视图并使它成为闪烁的蓝点的子视图吗?

这是我正在使用的代码,但我无法实现我的目标:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
/* guard statement would result in showing a blinking blue dot
instead of an annotationview.  I have commented it out
guard mode !(annotation is MKUserLocation) else {
print("the delegate function is not allowed to show user annotation")
return nil
}
*/
//This shows the annotationView with custom image but I am not getting the blinking dot.
let imageView = UIImageView(frame: CGRect(x: 0, y: 50, width: 50, height: 50))
imageView.image = UIImage(named: "myImage.png");
imageView.layer.cornerRadius = imageView.layer.frame.size.width / 2
imageView.layer.masksToBounds = true
annotationView.addSubview(imageView)
//      annotationView.superView.bringSubviewToFront(annotationView)

return annotationView
}

0 个答案:

没有答案