现在,当我选择注释时,我将视图重新定位到中心,如下所示:
[mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
但是如何重新定位我的视图以仅垂直居中而不是水平居中?
现在,当我选择注释时,我将视图重新定位到中心,如下所示:
[mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
但是如何重新定位我的视图以仅垂直居中而不是水平居中?
创建一个新坐标,该坐标具有注释中的纬度和当前经度
CLLocationCoordinate2D newCenter = CLLocationCoordinate2DMake(view.annotation.coordinate.latitude, mapView.centerCoordinate.longitude);
像以前一样设置它
[mapView setCenterCoordinate:newCenter animated:YES];
保留地图视图的 Y 但将 X 居中应该是这样的:
[mapView setCenterCoordinate:[self convertPoint:CGPointMake(view.annotation.coordinate.x /* or whatever x is in the coordinate sys*/, mapView.frame.origin.y) toCoordinateFromView:mapView] animated:YES];
将点转换为 CLLocationCoordinate2D:
- (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view
这应该对您的问题有所帮助。祝你好运。