注释视图不';t显示自定义图像-iOS9
我的viewForAnnotation在iOS8中运行良好,但在iOS9中不显示自定义pin图像。图像的路径正常。注释视图不';t显示自定义图像-iOS9,ios,swift,mkmapview,mapkit,mkannotation,Ios,Swift,Mkmapview,Mapkit,Mkannotation,我的viewForAnnotation在iOS8中运行良好,但在iOS9中不显示自定义pin图像。图像的路径正常。 怎么了?谢谢大家! func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? { if annotation is MKUserLocation { return nil //return nil so map vi
怎么了?谢谢大家!
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
}
改变
到
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)