2017-05-27 14 views
0

MapKitを使用していて、注釈の画像を変更しましたが、問題は、ユーザーの場所(青い点)も画像を変更したことです。どうすれば元の状態に戻すことができますか?また、(あなたが推測したように)私の場所に追加されたコールアウトに小さなボタンを追加しましたが、そこには存在しないはずです。(MapView)復元するヘルプの場所が変更されました

if annotation is MKUserLocation { 
    return nil 
} 

MKUserLocationをit's場合は、何をしたいドントので:私のコードは、最初にこの行を追加するには、viewFor annotation機能には、以下の...

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
     if !(annotation is MKUserLocation) { 
      print("annotation is MKUserLocation") 
     } 
     var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "identifier") 
      if annotationView == nil{ 
       annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "identifier") 
       annotationView!.canShowCallout = true 
       annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) 

       let pinImg = UIImage(named: "curz") 
       let size = CGSize(width: 50, height: 50) 
       UIGraphicsBeginImageContext(size) 
       pinImg!.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) 
       let resizedImage = UIGraphicsGetImageFromCurrentImageContext() 
       UIGraphicsEndImageContext() 
       annotationView!.image = resizedImage 
       } 
     else { 
     annotationView!.annotation = annotation 
     } 
    return annotationView 
    } 

     //Var SelectedAnnotation 
     var anotacionSeleccionada : MKPointAnnotation! 

    func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) { 
     if control == view.rightCalloutAccessoryView { 
     anotacionSeleccionada = view.annotation as? MKPointAnnotation 
     performSegue(withIdentifier: "vista", sender: self) 
     } 
     } 


    override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
     if let destination = segue.destination as? ViewController { 
     destination.pin = anotacionSeleccionada 
     } 
    } 

答えて

1

です。

+0

"if!(注釈はMKUserLocationです)"の代わりにその行を挿入しますか? –

+1

はい、@DanielCできます。 –

+0

それは動作します!ありがとうございました! –