iOS - MKMapView showAnnotations:animated: with padding?

后端 未结 4 1979
春和景丽
春和景丽 2020-12-14 21:53

I want to be able to zoom my MKMapView to fit it\'s annotations. I have managed to do it using iOS7\'s showAnnotations method. But I would also like to add some

4条回答
  •  天命终不由人
    2020-12-14 22:25

    another solution:

    extension MKMapView
    {
        func fitAllMarkers(inset: UIEdgeInsets? = nil) {
            self.showAnnotations(self.annotations, animated: false)
            OperationQueue.main.addOperation {
                self.setVisibleMapRect(self.visibleMapRect, edgePadding: inset ?? UIEdgeInsets.zero, animated: true)
            }
        }
    }
    

提交回复
热议问题