私はMKPointAnnotation
Sを使用していますスウィフトアプリケーションを作っていますに応答していない、と私は最近、私は私の注釈でメタデータを格納するために必要な問題に走ったので、私は以下のカスタムクラスを作成しました:カスタムMKPointAnnotationは、ユーザーとの対話
class BRETTFAnnotation: MKPointAnnotation {
var tag: Int64
var name: String
init(lat : Double, lon:Double, t : Int64, n: String) {
self.tag = t
self.name = n
super.init()
self.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
}
}
マイMKAnnotationView
MKAnnotation
viewfor方法を以下に示します。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
let newAnnotation = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "reuse")
newAnnotation.canShowCallout = true
let right = self.button(title: "Yes")
right?.addTarget(self, action: #selector(clickedToConfirmNewPoint), for: .touchUpInside)
newAnnotation.rightCalloutAccessoryView = right
let left = self.button(title: "No")
left?.addTarget(self, action: #selector(clickedToCancelNewPoint), for: .touchUpInside)
newAnnotation.leftCalloutAccessoryView = left
return newAnnotation
}
私は私に追加私のカスタムBRETTFAnnotation
(をクリックした今までにときに私はに実行している問題があります0)何も起こらない。 MKPointAnnotation
(BRETTFAnnotation
の代わりに)を使用していたときに、地図をクリックしたときにMKAnnotationView
の2つのボタンが表示されます。 MKPointAnnotation
の代わりにMKPinAnnotationView
を私のBRETTFAnnotation
を使用して接触して表示しようとしています。 注釈を同時にクリックしたときに、自分の注釈を引き続き使用して吹き出しを表示するにはどうすればよいですか?
編集1:以下のコードは、注釈を作成してmapViewに追加する方法です。
let location = gestureRecognizer.location(in: mapView)
let coordinate = mapView.convert(location,toCoordinateFrom: mapView)
print("adding lat,long \(coordinate.latitude),\(coordinate.longitude)")
lastPoint = BRETTFAnnotation(lat: coordinate.latitude, lon: coordinate.longitude, t: 1, n: "")
let annotationView = MKPinAnnotationView(annotation: lastPoint, reuseIdentifier: "reuse")
mapView.addAnnotation(lastPoint)
正確に何をしたいですか?アノテーションのクリックを処理するには、mapView(_ mapView:MKMapView、didSelectビュー:MKAnnotationView)を使用します。 – kuzdu
@kuzdu以前はこれを使用していませんでしたが、カスタム注釈をクリックすると、コールアウトは表示されません。私は、あなたが参照したものがうまくいくかどうかを説明してくれれば、どのような方法でもカスタムアノテーションのクリックを処理しようとしています。 – brettf