是否可以为MKMapView上的用户定位销设置一个固定的屏幕位置?

我试图build立一个MKMapView的方式,用户的位置将永远是偏移在视图控制器的右上angular,我将围绕该“块”构build我的用户界面的其余部分。

有没有办法为MKMapView设置一个固定/偏移中心点,例如,引脚始终位于屏幕上的x,y位置?

如果您无法理解我的目标,我可以提供一个草图示例。

我刚才知道了,

func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) { // Define a span (for zoom) let span: MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005) // Get user location let location = CLLocationCoordinate2D( latitude: userLocation.coordinate.latitude, longitude: userLocation.coordinate.longitude ) // Get the close region for the user's location // This zooms into the user's tracked location let region = MKCoordinateRegion(center: location, span: span) let adjusted = mapView.regionThatFits(region) mapView.setRegion(adjusted, animated: true) // Here we set the offset of the map to be 75% to the right // and 15% from the top. Gives us a nice top right view. var rect = mapView.visibleMapRect let point = MKMapPointForCoordinate(location) rect.origin.x = point.x - rect.size.width * 0.75 rect.origin.y = point.y - rect.size.height * 0.15 mapView.setVisibleMapRect(rect, animated: true) } 

巴勃罗答的答案是一个很好的起点,但可悲的是,这是不够的做我想找的东西。

我继续前进,并在地图视图顶部添加了遮罩视图,以便更好地直观地了解我最终要使用哪种UI。

MKMapView示例

您可以将像素坐标转换为地图坐标,以便知道添加引脚的位置,并在每次更改地图区域时进行更新:

 CGPoint fakecenter = CGPointMake(20, 20); CLLocationCoordinate2D coordinate = [mapView convertPoint:fakecenter toCoordinateFromView:mapView];