私はカスタムカラーサークルアノテーション(thisに基づく)の中に数字を描画することができました。カスタムアノテーションクラスの最適化をいくつか行い、再利用について読んでいます。 私の問題は、再利用可能なものを作ると、注釈ビューが大きな問題である地図上に混ざり合ってしまうことです。 カスタム描画アノテーションビューは再利用できません。または、それは何とかビューのannotionに関連していますか?つまり、アノテーションにはそのビューに描画される数値が格納されますが、実際には注釈とそのビューの間には1対1の関係があります。 カスタムannotationviewのinit:カスタム描画アノテーションビューの再利用
-(id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier imageType:(int)imageType {
self = [super initWithAnnotation: annotation reuseIdentifier: reuseIdentifier];
if (self != nil)
{
if ([annotation isKindOfClass:[CircleMarker class]])
{
// custom annotation class with some extra fields
CircleMarker * clm = (CircleMarker *)annotation;
self.locationMarker = clm;
// ... setting frame and other stuff
self.image = [self getImage]; /* this method DRAWS image based on clm */
self.canShowCallout = NO;
}
...
}
そしてデリゲート:ここ
は私の関連するコードです- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
static NSString *reuseId_small = @"smallcircle";
static NSString *reuseId_big = @"bigcircle";
CircleAnnotationView * nca = nil;
if ((int)[self.mapView getZoomLevel] < ZOOM_LEVEL_FOR_NUMBERS)
{
nca = (CircleAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseId_small];
if (nca == nil)
nca = [[[CircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId_small imageType:2] autorelease];
}
else
{
nca = (CircleAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseId_big];
if (nca == nil)
nca = [[[CircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId_big imageType:1] autorelease];
}
return nca;
}
私はカスタムdrawRect
機能でself.image =
部品を交換しようとしましたが、結果は同じでした。
ありがとうございました。
それとも内部で行くと、私は背景から引き出された番号を分ける必要があります参照
https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html
? – Templar