ピンの代わりに四角い友人のようなカスタムピンを作る方法は?4sqアプリのお友達のようなカスタムピンの作り方
画像は、ここにあなたがカスタムMKAnnotationViewを使用する必要がhttp://www.socialmedianews.com.au/wp-content/uploads/2010/07/foursquare-friends-map.png
ピンの代わりに四角い友人のようなカスタムピンを作る方法は?4sqアプリのお友達のようなカスタムピンの作り方
画像は、ここにあなたがカスタムMKAnnotationViewを使用する必要がhttp://www.socialmedianews.com.au/wp-content/uploads/2010/07/foursquare-friends-map.png
- (MKAnnotationView *)mapView:(MKMapView *)mv viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"pinView"];
if (!pinView) {
pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"] autorelease];
pinView.image = [UIImage imageNamed:@"SPOON4.png"];
pinView.frame = CGRectMake(-30, 0, 70, 67.5);
//pinView.animatesDrop = YES; can't animate with custom pin images
pinView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.rightCalloutAccessoryView = rightButton;
} else {
pinView.annotation = annotation;
}
if (annotation == mapView.userLocation){
return nil; //default to blue dot
}
return pinView;
}
です。
あなたはあるようMKAnnotationViewクラス を使用したり、必要に応じてカスタム 動作を提供するために、それをサブクラス化することができます。このクラスの画像プロパティ を使用すると、アノテーションビュー の外観を直接サブクラス化せずに に設定できます。 も便利な というカスタムサブクラスを作成し、それを使用して アノテーションビューを既知の状態にすることができます。 の例では、MKPinAnnotationView サブクラスは、 の内容をピン画像に初期化します。
カスタムピンをフレーム付きのポートレートで置き換える必要があります。 Quartzでフレームを描画したり、フレームを第2の透明な画像として追加することができます。私はMKAnnotationViewに、次の第2の加算を行うだろう:
- (id)initWithAnnotation:(id <MKAnnotation>)annotation
reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self != nil) {
self.opaque = NO;
self.frame = CGRectMake(0,0, self.portraitImage.size.width, self.portraitImage.size.height);
}
return self;
}
- (void)drawRect:(CGRect)rect {
[self.frameImage drawInRect:CGRectMake(0, 0, frameImage.width, frameImage.height)];
[self.portraitImage drawInRect:CGRectMake(0, 0, portraitImage.width, portraitImage.height)];
}
それは働きます!ありがとう。 – dobiho