因此,我在地图上有许多标记为注释的公共汽车站。我想使用公交站牌的图像,而不是默认的红色气泡或大头针,所以我成功地更改了图像。
这样做时,因为图像是512x512,所以我决定使用transform缩放MKAnnotationView。因此,当我选择一个公交车站时,详图索引编号现在也被缩放到相同的标高,这使得它不可读。
有没有什么方法可以只缩放图像而不缩放calloutView?
我的代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "stopPin")
annotationView.canShowCallout = true
annotationView.image = UIImage(named: "busStop.png")
let transform = CGAffineTransform(scaleX: 0.25, y: 0.25)
annotationView.transform = transform
return annotationView
}发布于 2018-01-26 20:59:52
使用UIGraphics。
let image = UIImage(named: "busStop.png")
let resizedSize = CGSize(width: 100, height: 100)
UIGraphicsBeginImageContext(resizedSize)
image?.draw(in: CGRect(origin: .zero, size: resizedSize))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
annotationView?.image = resizedImagehttps://stackoverflow.com/questions/48460081
复制相似问题