Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 旋转或放大/缩小地图时,自定义MKAnnotationView位置会发生剧烈变化_Ios_Objective C_Swift_Mkmapview_Mkannotationview - Fatal编程技术网

Ios 旋转或放大/缩小地图时,自定义MKAnnotationView位置会发生剧烈变化

Ios 旋转或放大/缩小地图时,自定义MKAnnotationView位置会发生剧烈变化,ios,objective-c,swift,mkmapview,mkannotationview,Ios,Objective C,Swift,Mkmapview,Mkannotationview,我有两个自定义的MKAnnotationViews,当它们最初添加到MKMapView时,显示良好 问题是,当旋转或缩小时,它们绘制的位置似乎变得越来越模糊。再次重申,我放大得越近,它们显示得越准确,但在缩小和旋转时,它们完全关闭。有什么想法吗 看起来不错(初始状态): 看起来很糟糕(而且是错误的): 我的viewForAnnotation方法非常基本,这里没有什么特别之处 func mapView(_ mapView: MKMapView, viewFor annotation: MKAn

我有两个自定义的
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)
修复了“驻车销注释视图”旋转,但与驾驶员注释视图(带汽车的视图)没有关系

非常感谢你的帮助

您应该设置
MKAnnotationView
的。正如文件所说:

默认情况下,注释视图的中心点放置在关联注释的坐标点上。可以根据需要使用此特性重新定位注释视图。该x和y偏移值以点为单位测量。正偏移值将注释视图向下和向右移动,而负值将注释视图向上和向左移动


对于driver annotation视图,我认为坐标点应该是视图的中心,因为它位于一个正方形内,并且横跨整个视图,因此更改中心偏移将有何帮助?对于管脚注释视图,我能够解决更新中提到的锚定点调整问题。我不会更改锚定点。这就是中心偏移量的目的。好吧,假设我的驾驶员注释视图是100 x 100点,我相信你会将中心偏移量设置为0,50?0,-50,以将其向上移动。汽车前部位于顶部,因此向下看起来更合理?