ฉันมี MKAnnotationViews
แบบกำหนดเองสองตัว ซึ่งแสดงผลได้ดีเมื่อเพิ่มลงใน MKMapView
ในตอนแรก
ปัญหาคือเมื่อหมุนหรือซูมออก ตำแหน่งที่วาดไว้ดูเหมือนจะผิดเพี้ยนมากขึ้นเรื่อยๆ ขอย้ำอีกครั้งว่ายิ่งฉันซูมเข้าไปใกล้เท่าใด พวกมันก็จะยิ่งปรากฏได้แม่นยำมากขึ้นเท่านั้น แต่เมื่อซูมออกและหมุนพวกมันก็จะปิดสนิท มีความคิดอะไรบ้าง?
ดูดี (สถานะเริ่มต้น):
ดูไม่ดี (และผิด):
วิธีการ viewForAnnotation
ของฉันค่อนข้างธรรมดา ไม่มีอะไรพิเศษเกิดขึ้นที่นี่
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
}
อัปเดต
ฉันสงสัยว่าสิ่งนี้ค่อนข้างเกี่ยวข้องกับจุดยึด และฉันสามารถแก้ไขการหมุน "มุมมองคำอธิบายประกอบของหมุดจอดรถ" ได้ด้วย view.layer.anchorPoint = CGPoint(x: 0.5, y: 1.0)
แต่ไม่มีโชคกับมุมมองคำอธิบายประกอบของผู้ขับขี่ (ที่มีรถยนต์)
ขอบคุณสำหรับความช่วยเหลือ SO!