选择注释时,如何仅将视图设置为垂直居中

Pav*_*nen 1 annotations center mkmapview ios

现在,当我选择注释时,我将视图重新定位为居中,如下所示:

[mapView setCenterCoordinate:view.annotation.coordinate animated:YES];
Run Code Online (Sandbox Code Playgroud)

但是,如何才能将视图重新定位到垂直而不是水平居中?

Cra*_*aig 6

创建一个具有注释和当前经度纬度的新坐标

CLLocationCoordinate2D newCenter = CLLocationCoordinate2DMake(view.annotation.coordinate.latitude, mapView.centerCoordinate.longitude);
Run Code Online (Sandbox Code Playgroud)

像以前一样设置它

[mapView setCenterCoordinate:newCenter animated:YES];
Run Code Online (Sandbox Code Playgroud)