【问题标题】:How to change size of annotation on move the map?如何在移动地图时更改注释的大小?
【发布时间】:2018-02-18 14:37:06
【问题描述】:

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

【问题讨论】:

    标签: swift mkmapview mkannotation mkannotationview


    【解决方案1】:

    您可以使用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
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-10
      • 2016-12-26
      • 1970-01-01
      • 2022-12-11
      • 2013-05-08
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多