简体   繁体   English

MKPointAnnotation与图像,通过按钮插入注释,图像不出现

[英]MKPointAnnotation with image, insert annotation via Button, image doesn't appear

When I press my button, I want to add an annotation to my mapview. 当我按下按钮时,我想在地图视图中添加注释。

   let annotation = MKPointAnnotation()

    annoation.coordinate = (myrightCoordinates)

    let annoationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "ident")
    annoationView.image = UIImage(named: "single_base")

    mapView.addAnnotation(annoationView.annotation!)

My annoation appears, but not the image. 我的烦恼出现了,但没有图像。 What's wrong? 怎么了? The image name is correct, I check this minimum five times -.- I googled a lot and found everytime snippets like that. 图片名称正确无误,我至少检查了五次-.-我在Google上搜索了很多,每次都发现这样的摘要。 I want to solve that without CustomAnnotationClass or something like this. 我想解决的问题没有CustomAnnotationClass或类似的东西。

Thanks for help :) 感谢帮助 :)

// i think it will help for you. //我认为这对您有帮助。

let annotation = MKPointAnnotation()

annoation.coordinate = (myrightCoordinates)

let annoationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "ident")
annoationView.tag = 111
mapView.addAnnotation(annoationView.annotation!)
// need to give tag value if you have multiple annotations 
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let pinImageAnnotation: MKAnnotationView = MKAnnotationView(annotation:annotation, reuseIdentifier:"pinImageAnnotation")
if annotation.tag == 111 {
    pinImageAnnotation.image = UIImage(named: "single_base")
}
return pinImageAnnotation
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM