0
我想要一個自定義的註釋視圖,其行爲與標準視圖完全一樣,但我的圖像需要內部和幾個文本,這就是爲什麼我已經實現了教程http://developer.apple.com/library/ios/#samplecode/WeatherMap/Introduction/Intro.htmlobjective c - 隱藏自定義註釋視圖
但我的問題是,我想要註釋視圖隱藏,只顯示一個別針,與默認註釋視圖的行爲相同的事情,但所有註釋顯示,我不知道一種方法來隱藏它們。
任何想法?
謝謝。
[編輯] 我的當前實現viewForAnnotation的是:
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation{
NSLog(@"Item añadido");
static NSString *AnnotationViewID = @"annotationViewID";
CustomMKAnnotationView *annotationView =
(CustomMKAnnotationView *)[mapa dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[CustomMKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.annotation = annotation;
return annotationView;
}
監守我需要的標準泡沫,但與圖像和幾個UILabels的。但我想保持標準的行爲,也就是說,當泡沫沒有顯示時有一個針,當你點擊它時顯示泡沫。我的自定義氣泡的內容在「CustomMKAnnotationView」中實現。 主要內容如下:
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self != nil)
{
CGRect frame = self.frame;
frame.size = CGSizeMake(10.0, 10.0);
self.frame = frame;
// self. = [super pincolor];
self.backgroundColor = [UIColor clearColor];
self.centerOffset = CGPointMake(10.0, 10.0);
}
return self;
}
- (void)drawRect:(CGRect)rect{
CustomMKAnnotation *custom = (CustomMKAnnotation *)self.annotation;
if (custom != nil)
{
NSLog(@"El nombre es: %@", [custom nombre]);
UILabel *nombre = [[UILabel alloc]init];
UILabel *media = [[UILabel alloc]init];
PDColoredProgressView *barrita = [[PDColoredProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[barrita setTintColor:[UIColor colorWithRed:0.6 green:0.83 blue:0.91 alpha:1.0f]];
nombre.textColor = [UIColor whiteColor];
media.textColor = [UIColor whiteColor];
nombre.font = [UIFont fontWithName:@"DIN-Bold" size:14];
media.font = [UIFont fontWithName:@"DIN-Medium" size:12];
CGSize size = [[custom nombre] sizeWithFont:nombre.font constrainedToSize:CGSizeMake(300, 20) lineBreakMode:nombre.lineBreakMode];
NSLog(@"el ancho es: %f y alto %f", size.width, size.height);
nombre.backgroundColor = [UIColor clearColor];
media.backgroundColor = [UIColor clearColor];
nombre.text = [custom nombre];
barrita.progress = [custom gente];
media.text = [NSString stringWithFormat:@"Media %@ años", [custom media]];
UIImageView *fondo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bubble_map.png"]];
nombre.frame = CGRectMake(10, 10, size.width, size.height);
media.frame = CGRectMake(10, size.height + 10, size.width, size.height);
barrita.frame = CGRectMake(10, media.frame.origin.y + 20, size.width, 10);
fondo.frame = CGRectMake(-((size.width+ 20.0f)/2), -((size.height +10)*2 + 20)-10, size.width+ 20.0f, (size.height +10)*2 + 20);
fondo.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
nombre.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[fondo addSubview:nombre];
[fondo addSubview:media];
[fondo addSubview:barrita];
[self addSubview:fondo];
[fondo release];
[nombre release];
[media release];
}
}
我添加了一些代碼,以使其更清晰什麼我試着,這是basicly模仿annotationview,但與我的自定義註解的看法,我需要引腳的標準行爲,並還有那些在點擊時顯示氣泡的針腳。 – subharb 2012-01-13 14:56:13
對不起,但我仍然不清楚你的問題,你有一個別針,當你點擊它,你會得到圖像和細節的泡沫?那麼你究竟需要什麼? – iNoob 2012-01-13 15:28:41
對不起,我現在試着更加清楚。我粘貼的代碼在地圖泡泡中「繪製」,沒有任何針。氣泡膨脹,所以如果我有5個地點,地圖上就會出現氣泡。 我需要一個類似於標準的行爲。也就是說,它首先「繪製」引腳,當你點擊任何引腳時,顯示的是我已經實現的包含幾個uilabels和圖像的Custom Annotation。目前的實現不顯示引腳,氣泡已經擴大。 – subharb 2012-01-14 17:38:59