[英]How to change the custom pin image while zooming in MKMapView?
我用过swift 4
。 我正在使用MKMapkit
并且为地图图钉添加了自定义注释图像。 问题是,
假设我有2个图像,例如image1
和image2
。 最初,将为所有映射图钉加载image1。 现在,如果要放大到地图视图,则需要将image1
替换为image2
。 同样,如果要缩小图像,则需要将image2
替换为image
1。
那么,如果有人知道该怎么做?
我有类似的问题,我这样解决
首先在地图委托中实现regionDidChangeAnimated
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
calculateZoomFactor()//Create global var named zoomFactor
print("*************************")
if zoomFactor > x { //Change the x value as you wish
print("Zoom close, you can remove your annotations, and create with new image2")
} else {
print("Zoom out, remove annotations, and add new annotations with image 1")
}
print("*************************")
}
这是我自定义的zoomFactor计算器
func calculateZoomFactor() {
let zoomWidth = mapView.visibleMapRect.size.width
let zoomFactor = (log2(zoomWidth)) - 8.785//You can change this constant also
self.zoomFactor = zoomFactor
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.