我如何垂直给定数量的像素滑动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)
答案 0 :(得分:1)
刚想出来,这是代码,希望它会帮助别人;)
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))