Saya punya dua MKAnnotationViews
khusus, yang ditampilkan dengan baik saat pertama kali ditambahkan ke MKMapView
.
Masalahnya adalah, saat memutar, atau memperkecil, lokasi yang digambar tampak semakin menjauh. Sekali lagi, semakin dekat saya memperbesar, semakin akurat tampilannya, namun saat memperkecil dan memutar, tampilannya tidak aktif sama sekali. Ada ide?
Terlihat bagus (keadaan awal):
Terlihat buruk (dan salah):
Metode viewForAnnotation
saya cukup mendasar, tidak ada hal mewah yang terjadi di sini.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? PKDriverAnnotation
{
let identifier = "driver"
var annotationView: PKDriverAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) { // 2
dequeuedView.annotation = annotation
annotationView = dequeuedView as! PKDriverAnnotationView
} else {
// 3
annotationView = PKDriverAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(PKTransactionMapViewController.annotationViewTapped(recognizer:))))
}
self.driverAnnotationView = annotationView
return annotationView
} else if let annotation = annotation as? PKAnnotation {
let identifier = "pin"
var view: MKAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) { // 2
dequeuedView.annotation = annotation
view = dequeuedView
} else {
// 3
view = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.image = UIImage(named: "TransactionAnnotation")
view.canShowCallout = false
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(PKHomeViewController.annotationViewTapped(recognizer:))))
let profilePic = FBSDKProfilePictureView(frame: CGRect(x: 4, y: 4, width: 43, height: 43))
profilePic.center = CGPoint(x: view.bounds.midX, y: profilePic.center.y)
profilePic.profileID = self.transaction!.availableParking.holder.fbid
profilePic.layer.cornerRadius = 21.0
profilePic.clipsToBounds = true
view.addSubview(profilePic)
}
return view
}
return nil
}
Memperbarui
Saya curiga ini ada hubungannya dengan titik jangkar, dan saya dapat memperbaiki rotasi "tampilan anotasi pin parkir" sebanyak view.layer.anchorPoint = CGPoint(x: 0.5, y: 1.0)
, tetapi tidak berhasil dengan tampilan anotasi pengemudi (yang ada mobilnya)
Hargai bantuannya JADI!