小编Fel*_*ber的帖子

MapKit没有在iOS9上显示自定义注释图钉图像

从iOS 7到8,我的代码运行良好.昨天更新了我的引脚上的自定义图像被标准引脚图像替换.有什么建议?

我的代码:

extension ViewController: MKMapViewDelegate {

    func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView! {

        if annotation is MKUserLocation {
            return nil
        }

        let reuseId = String(stringInterpolationSegment: annotation.coordinate.longitude)

        var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView

        if pinView == nil {

            pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
            pinView!.canShowCallout = true
            pinView!.image = getRightImage(annotation.title!!) 
        }

        let button = UIButton(type: UIButtonType.DetailDisclosure) 
        pinView?.rightCalloutAccessoryView = button

        return pinView
    }
}
Run Code Online (Sandbox Code Playgroud)

获取图像的函数UIImage根据名称返回:

func getRightImage (shopName:String)-> UIImage{

    var correctImage = UIImage()

    switch shopName
    {
    case …
Run Code Online (Sandbox Code Playgroud)

mapkit mkmapview mkannotation mkannotationview ios9

35
推荐指数
2
解决办法
1万
查看次数

标签 统计

ios9 ×1

mapkit ×1

mkannotation ×1

mkannotationview ×1

mkmapview ×1