
我的工作循环和某些尝试…
....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()所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)