【发布时间】:2017-07-04 18:23:59
【问题描述】:
我有两个自定义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) 修复“停车销注释视图”旋转,但驾驶员注释视图(与汽车的视图)没有运气
感谢您的帮助!
【问题讨论】:
标签: ios objective-c swift mkmapview mkannotationview