ios – 在Swift和MapKit中使用MKPinAnnotationView()

ios – 在Swift和MapKit中使用MKPinAnnotationView(),第1张

概述我有一个工作循环为一些工作数据点设置标题和字幕元素的注释.在同一循环结构中我想做的是将引脚颜色设置为紫色而不是默认值.我不知道的是,我需要做的是点击我的mapView来相应地设置引脚. 我的工作循环和某些尝试… ....for var index = 0; index < MySupplierData.count; ++index { // Establish an Annotation 我有一个工作循环为一些工作数据点设置标题和字幕元素的注释.在同一循环结构中我想做的是将引脚颜色设置为紫色而不是默认值.我不知道的是,我需要做的是点击我的mapVIEw来相应地设置引脚.

我的工作循环和某些尝试…

....for var index = 0; index < MysupplierData.count; ++index {  // Establish an Annotation  myAnnotation = MKPointAnnotation();  ... establish the coordinate,Title,subTitle propertIEs - this all works  self.theMapVIEw.addAnnotation(myAnnotation)  // this works great.  // In thinking about PinVIEw and how to set it up I have this...  myPinVIEw = MKPinAnnotationVIEw();        myPinVIEw.animatesDrop = true;  myPinVIEw.pincolor = MKPinAnnotationcolor.Purple;    // Now how do I get this vIEw to be used for this particular Annotation in theMapVIEw that I am iterating through??? Somehow I need to marry them or kNow how to replace these attributes directly without the above code for each data point added to the vIEw  // It would be nice to have some kind of addPinVIEw.  }
解决方法 您需要实现vIEwForAnnotation委托方法并返回一个MKAnnotationVIEw(或子类).
这就像在Objective-C中 – 底层SDK的工作方式相同.

从添加注释的for循环中删除MKPinAnnotationVIEw的创建,并实现代理方法.

以下是Swift中的VIEwForAnnotation委托方法的示例实现:

func mapVIEw(mapVIEw: MKMapVIEw!,vIEwForAnnotation annotation: MKAnnotation!) -> MKAnnotationVIEw! {    if annotation is MKUserLocation {        //return nil so map vIEw draws "blue dot" for standard user location        return nil    }    let reuseID = "pin"    var pinVIEw = mapVIEw.dequeueReusableAnnotationVIEwWithIDentifIEr(reuseID) as? MKPinAnnotationVIEw    if pinVIEw == nil {        pinVIEw = MKPinAnnotationVIEw(annotation: annotation,reuseIDentifIEr: reuseID)        pinVIEw!.canShowCallout = true        pinVIEw!.animatesDrop = true        pinVIEw!.pincolor = .Purple    }    else {        pinVIEw!.annotation = annotation    }    return pinVIEw}
总结

以上是内存溢出为你收集整理的ios – 在Swift和MapKit中使用MKPinAnnotationView()全部内容,希望文章能够帮你解决ios – 在Swift和MapKit中使用MKPinAnnotationView()所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1113233.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存