スクロールしても、あなたのMapViewの中央に目印/注釈を持ちますあなたの地図ビュー、あなたが地図をスクロールすると、目印は常に中央にとどまるべきです。あなたは、私がこれを行う方法を把握しようと多くの時間を費やしてきた
私もこれをやっている別のアプリを見ました!
スクロールしても、あなたのMapViewの中央に目印/注釈を持ちますあなたの地図ビュー、あなたが地図をスクロールすると、目印は常に中央にとどまるべきです。あなたは、私がこれを行う方法を把握しようと多くの時間を費やしてきた
私もこれをやっている別のアプリを見ました!
は答えがありますHow to add annotation on center of map view in iPhone?
で、私の質問が見つかりました:
マップビューの中心部の上方に位置するだけで通常のビューのではなく、実際のアノテーションを使用したい場合は、次のことができます。
MKPointAnnotation
クラスなど)を持つアノテーションクラスを使用します。これにより、中心が変更されたときにアノテーションを削除して追加する必要がなくなります。regionDidChangeAnimated
デリゲートメソッドでcenterAnnotation例:
@interface SomeViewController : UIViewController <MKMapViewDelegate> {
MKPointAnnotation *centerAnnotation;
}
@property (nonatomic, retain) MKPointAnnotation *centerAnnotation;
@end
@implementation SomeViewController
@synthesize centerAnnotation;
- (void)viewDidLoad {
[super viewDidLoad];
MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];
pa.coordinate = mapView.centerCoordinate;
pa.title = @"Map Center";
pa.subtitle = [NSString stringWithFormat:@"%f, %f", pa.coordinate.latitude, pa.coordinate.longitude];
[mapView addAnnotation:pa];
self.centerAnnotation = pa;
[pa release];
}
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
centerAnnotation.coordinate = mapView.centerCoordinate;
centerAnnotation.subtitle = [NSString stringWithFormat:@"%f, %f", centerAnnotation.coordinate.latitude, centerAnnotation.coordinate.longitude];
}
- (void)dealloc {
[centerAnnotation release];
[super dealloc];
}
@end
さて、これはスムーズに注釈を移動しなくなります。あなたがよりスムーズに移動する注釈が必要な場合は、マップビューにUIPanGestureRecognizer
とUIPinchGestureRecognizer
を追加しても、ジェスチャーハンドラ内で注釈を更新することができます。
// (Also add UIGestureRecognizerDelegate to the interface.)
// In viewDidLoad:
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
panGesture.delegate = self;
[mapView addGestureRecognizer:panGesture];
[panGesture release];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
pinchGesture.delegate = self;
[mapView addGestureRecognizer:pinchGesture];
[pinchGesture release];
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer
{
centerAnnotation.coordinate = mapView.centerCoordinate;
centerAnnotation.subtitle = [NSString stringWithFormat:@"%f, %f", centerAnnotation.coordinate.latitude, centerAnnotation.coordinate.longitude];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
//let the map view's and our gesture recognizers work at the same time...
return YES;
}
これは、上の例のようにズームしたときにピンを中央に置いているようには見えません。 –
参照[この質問](http://stackoverflow.com/questions/6504536/add-to-add-on-map-in-iphoneの注釈)。 – Anna
@AnnaKareninaありがとう、ちょうど私が探していたものです! – Marc
@Annaこれは答えのようです。あなたはポストをお願いしますので、OPはそれを受け入れることができますか? – NGLN