Ste*_*ell 3 mkmapview mkannotation ios swift
我已经按照其他堆栈帖子和教程将我的注释图像更改为自定义图像,但它似乎不起作用.不会出现错误或运行时错误,只是注释图像不会改变.
顺便说一下,我在线上设置了一个断点annotationView!.image = UIImage(named: "RaceCarMan2png.png"),它显示了该线被调用,但是没有任何反应.我将衷心感谢您的帮助.谢谢.
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let identifier = "MyCustomAnnotation"
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView?.canShowCallout = true
annotationView!.image = UIImage(named: "RaceCarMan2png.png")
} else {
annotationView!.annotation = annotation
}
configureDetailView(annotationView!)
return annotationView
}
func configureDetailView(annotationView: MKAnnotationView) {
annotationView.detailCalloutAccessoryView = UIImageView(image: UIImage(named: "url.jpg"))
}
Run Code Online (Sandbox Code Playgroud)
Rob*_*Rob 10
问题是你正在使用MKPinAnnotationView.如果您使用MKAnnotationView,您将看到您的图像:
__PRE__
产量:
在过去的(如iOS版8),设置image的MKPinAnnotationView似乎正常工作,但在iOS的9.x中,似乎使用针不管.对于一个被调用的类来说MKPinAnnotationView,这并不是完全不合理的行为,并且使用MKAnnotationView避免了这个问题.
| 归档时间: |
|
| 查看次数: |
3275 次 |
| 最近记录: |