幻灯片的MKMapView中规定的像素数向下或向上

问题描述:

我怎么会滑动的MKMapView通过像素的给定数量的垂直,我打它了一下周围,这里是我的代码,这offcourse不工作:(幻灯片的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))