1

ここで、注釈を選択すると、次のようにビューを中央に再配置します。

[mapView setCenterCoordinate:view.annotation.coordinate animated:YES];

しかし、ビューを水平方向ではなく垂直方向のみの中央に再配置するにはどうすればよいですか?

4

2 に答える 2

6

注釈からの緯度と現在の経度を持つ新しい座標を作成します

CLLocationCoordinate2D newCenter = CLLocationCoordinate2DMake(view.annotation.coordinate.latitude, mapView.centerCoordinate.longitude);

以前と同じように設定します

[mapView setCenterCoordinate:newCenter animated:YES];
于 2012-08-17T20:35:27.123 に答える
1

マップビューの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

これはあなたの問題をいくらか助けるはずです。幸運を。

于 2012-08-17T11:28:21.713 に答える