MKPointAnnotations touch-event in swift

Ich würde gerne wissen, ob jemand mir sagen kann, wie kann ich touch ein pin auf der map in form von MKPointAnnotations .

Möchte ich Sie auf die pin auf die map und gehen Sie zu einer anderen Ansicht, indem wieder die variables des pin dass ich die Vorgabe .

Kann jemand erklären Sie mir das Ding in Swift ?

Dank

Bearbeiten mit code:

class ViewController: UIViewController, MKMapViewDelegate {


@IBOutlet weak var mappa: MKMapView!


override func viewDidLoad() {
    super.viewDidLoad()

    var location : CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 44.648590, longitude: 10.918794)

    let pinAnnotation = PinAnnotation()
    pinAnnotation.setCoordinate(location)

    self.mappa.addAnnotation(pinAnnotation)

}

class PinAnnotation : NSObject, MKAnnotation {
    private var coord: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0, longitude: 0)

    var coordinate: CLLocationCoordinate2D {
        get {
            return coord
        }
    }

    var title: String = "test"
    var subtitle: String = "test"

    func setCoordinate(newCoordinate: CLLocationCoordinate2D) {
        self.coord = newCoordinate
    }        
}

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
    if annotation is PinAnnotation {
        let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")

        pinAnnotationView.pinColor = .Purple
        pinAnnotationView.draggable = true
        pinAnnotationView.canShowCallout = true
        pinAnnotationView.animatesDrop = true

        let deleteButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
        deleteButton.frame.size.width = 44
        deleteButton.frame.size.height = 44
        deleteButton.backgroundColor = UIColor.redColor()
        deleteButton.setImage(UIImage(named: "trash"), forState: .Normal)

        pinAnnotationView.leftCalloutAccessoryView = deleteButton


        return pinAnnotationView
    }

    return nil
}

func mapView(mapView: MKMapView!, annotationView view: MKAnnotationView!, calloutAccessoryControlTapped control: UIControl!) {
    if let annotation = view.annotation as? PinAnnotation {
        self.mapView.removeAnnotation(annotation)
    }
}
}
  • Wenn die annotation der Titel ist leer, Legende wird nicht angezeigt, wenn Sie Tippen Sie darauf.
  • Ich fügte die Anmerkung , und ein text geschrieben , das popup kommt heraus richtig, aber tut nichts .. Sie wissen warum?
  • Vielleicht ist die map-Ansicht delegieren Steckdose ist nicht angeschlossen/eingestellt.
  • Ich kann bestätigen, dass es verbunden ist, mehr als alles andere , ich Frage mich, wo ich mit der Methode MapView , sind neu in der Sprache und können nicht verstehen, wie er kann, verlassen Sie diese Methode, wenn Sie nicht aufrufen ... danke
Schreibe einen Kommentar