2015-11-05 138 views
1

我的viewForAnnotation在iOS8中工作正常,但不顯示iOS9中的自定義圖釘圖像。圖像的路徑是好的。
什麼錯?謝謝 !viewForAnnotation不顯示自定義圖像 - iOS9

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { 
    if annotation is MKUserLocation { 
     return nil //return nil so map view draws "blue dot" for standard user location 
    } 

    let reuseId = "pin" 
    var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) 

    if pinView == nil { 
     pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
     pinView!.canShowCallout = true 

    }else{ 
     pinView!.annotation = annotation 
    } 
    if annotation is MyAnnotation { 
     let myPin = annotation as! MyAnnotation 

     // Custom image in bubble 
     let viewLeftAccessory = UIView(frame: CGRectMake(0, 0, pinView!.frame.size.height + 20, pinView!.frame.size.height + 20)) 
     let temp = UIImageView(frame: viewLeftAccessory.frame) 
     temp.image = UIImage(named: myPin.iconName) 
     viewLeftAccessory.addSubview(temp) 
     pinView!.leftCalloutAccessoryView = viewLeftAccessory 

     pinView!.image = UIImage(named: "BluePin") 
     pinView!.rightCalloutAccessoryView = UIButton(type: UIButtonType.DetailDisclosure) as UIView 

     return pinView 
    } 
    return nil 
} 

回答

2

變化

pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 

pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
+0

的作品就像一個魅力 – user3722523

相關問題