【问题标题】:Size of custom MKPointAnnotation自定义 MKPointAnnotation 的大小
【发布时间】:2019-12-23 19:49:22
【问题描述】:

我对自定义 MKAnnotationView 的大小有疑问。 我设置了一个自定义图像,但是当 MKMapView 的缩放更改注释的大小时不会。 我失去了注释的默认行为,例如在缩放、调整大小等方面消失。 感谢您的帮助。

我的自定义注释:

class CustomPointAnnotation: MKPointAnnotation {
var pinCustomImageName:String!
var index : Int! }


func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    let reuseIdentifier = "pin"
    var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseIdentifier)
    annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseIdentifier)

    annotationView?.canShowCallout = true;
    let customPointAnnotation = annotation as! CustomPointAnnotation

    var image = UIImage(named: customPointAnnotation.pinCustomImageName)
    annotationView?.image = image
    annotationView!.isEnabled = true
    annotationView!.canShowCallout = true
    return annotationView
    }

编辑: 我只想在放大或缩小地图时调整注释视图的大小。当我离开时,注解消失了。

【问题讨论】:

标签: swift mapkit mkmapview mkannotation mkannotationview


【解决方案1】:

使用 displayPriority 使注释消失

 annotationView?.displayPriority = .defaultHigh

static let required: MKFeatureDisplayPriority 一个常量,表明该项目是必需的。

静态让 defaultHigh: MKFeatureDisplayPriority 一个常数,表示项目的显示优先级很高。

静态让 defaultLow: MKFeatureDisplayPriority 一个常数,表示项目的显示优先级低。 Apple documentation

【讨论】:

    猜你喜欢
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多