2017-05-09 4 views
0

マップキットの現在地のドットにリアルタイムで反応したいと考えています。私は、LocationManagerを使用して間隔で位置を取得することができますが、注釈はより流動的な方法で移動します。私はこの動きを捉えたい。私の場合、MKPolylineエンドポイントに接続することで、ドットUIViewの位置を観察する方法や反応する方法がありますか?Mapkitオブジェクト値の変更に反応する

答えて

0

あなたはそれにオブザーバーを追加し、独自のユーザー・ロケーション・ビューを作成する必要があります:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ClubPinAnnotation *)annotation { 

    // If the annotation is the user location, create and return our own dot view 
    if ([annotation isKindOfClass:[MKUserLocation class]]) {    
     MKAnnotationView *userView = [[MKAnnotationView alloc] initWithFrame:CGRectMake(-5, -5, 10, 10)]; 
     userView.layer.cornerRadius = 5; 
     userView.backgroundColor = [UIColor blueColor]; 

     // Observe its on-screen position 
     [userView addObserver:self forKeyPath:@"layer.position" options:NSKeyValueObservingOptionNew context:nil]; 

     return userView; 
    } 

    ... continue processing the other map annotations 
} 

はその後、画面上のピンの位置を守ってください。

- (void)observeValueForKeyPath:(NSString *)keyPath 
         ofObject:(id)object 
         change:(NSDictionary *)change 
         context:(void *)context { 

    MKAnnotationView *userView = (MKAnnotationView *)object; 

    NSLog(@"User view:%@", userView); 
} 
+0

p.s.申し訳ありませんがObjective-Cで答えましたが、そのアイデアは同じです。 – norders

0

アニメーション補間された応答である可能性が高い。私はこれをサポートするための研究がないので、私の推測です。

アニメーション期間を見積もり、MkPolylineを補間領域の計算値としてアニメーション期間の時間の関数として提供することができます。

関連する問題