gpt4 book ai didi

swift - 如何在移动 map 时更改注释的大小?

转载 作者:行者123 更新时间:2023-11-30 11:45:38 25 4
gpt4 key购买 nike

我正在使用 swift 开发一个 iOS 应用程序。该应用程序包含一个带有自定义注释 View 的 MKMapView。我想根据到 View 中心的距离更改注释的大小。我知道我可以使用类似 view.transform = CGAffineTransform(scaleX:transformFaktor, y:transformFaktor) 的东西,但我不知道将其放置在哪里以及如何从注释中获取 View 。

最佳答案

您可以使用UIGraphics更改注释的大小。

例如

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}

let image = UIImage(named: "Image name here")
let resizedSize = CGSize(width: 100, height: 100)

UIGraphicsBeginImageContext(resizedSize)
image?.draw(in: CGRect(origin: .zero, size: resizedSize))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "Pin")
annotationView.image = resizedImage
return annotationView
}

关于swift - 如何在移动 map 时更改注释的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48852826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com