向下或向上滑动 MKMapView 指定数量的像素

Slide MKMapView specified number of pixels down or up

我如何将 MKMapView 垂直滑动给定的像素数,我玩了一下,这是我的代码,当然这不起作用:(

var point = mapView.convert(mapView.centerCoordinate, toPointTo: self.view)

point.x += offSet.x
point.y += offSet.y

let center = mapView.convert(point, toCoordinateFrom: self.view)
mapView.setCenter(center, animated: true)

刚弄明白,这是代码,希望对大家有所帮助;)

func mapViewMoveBy(offset: CGPoint, animated: Bool = true) {
    var point = mapView.center

    point.x += offset.x
    point.y += offset.y

    let coordinate = mapView.convert(point, toCoordinateFrom: mapView)
    mapView.setCenter(coordinate, animated: animated)
}

用法

let slideFourtyPixelDown: CGFloat = -40
mapViewMoveBy(offset: CGPoint(x: 0, y: slideFourtyPixelDown))