I love iPhone, Android, Cocos2d-x
[iPhone] 地図にピンが落ちてくるアニメーション
Map.app のようにピンが上から落ちてくるアニメーションを MapKit で実装する方法です。
ピンのアノテーション
MKPinAnnotationView の場合は簡単です。animatesDrop = YES を指定するだけです。
-(MKAnnotationView*)mapView:(MKMapView*)_mapView viewForAnnotation:(id)annotation { if (annotation == mapView.userLocation) { return nil; } MKPinAnnotationView *annotationView; NSString* identifier = @"Pin"; annotationView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; if(nil == annotationView) { annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease]; } annotationView.animatesDrop = YES; return annotationView; }
独自アイコンのアノテーション
MKAnnotation を使用して自分で指定した画像をアイコンにしている場合は、animatesDrop を指定できません。MKPinAnnotation のプロパティなので、指定するとエラーになります。MKPinAnnotation は MKAnnotation のサブクラスです。
MKAnnotation の場合は mapView: didAddAnnotationViews: を使用して自分でアニメーションの設定をします。下記のコードはピンがおちてくるのと同じ様なアニメーションを指定しています。
- (void)mapView:(MKMapView *)_mapView didAddAnnotationViews:(NSArray *)views {
CGRect visibleRect = [mapView annotationVisibleRect];
for (MKAnnotationView *view in views) {
CGRect endFrame = view.frame;
CGRect startFrame = endFrame;
startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
view.frame = startFrame;
[UIView beginAnimations:@"drop" context:NULL];
view.frame = endFrame;
[UIView commitAnimations];
}
}
関連する投稿
One comment
3tuneful への返信 コメントをキャンセル
Additional comments powered by BackType
3tendril…
…