Objective c 目标c-隐藏自定义注释视图

Objective c 目标c-隐藏自定义注释视图,objective-c,Objective C,我希望有一个自定义的注释视图,其行为与标准视图完全相同,但我的视图需要有一个图像和多个文本,这就是我在上实现教程的原因 但我的问题是,我希望注释视图隐藏并仅显示一个pin,这与默认注释视图的行为相同,但所有注释都在显示,我无法找到隐藏它们的方法 有什么想法吗 谢谢 [编辑] 我目前对viewForAnnotation的实现是: - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation

我希望有一个自定义的注释视图,其行为与标准视图完全相同,但我的视图需要有一个图像和多个文本,这就是我在上实现教程的原因

但我的问题是,我希望注释视图隐藏并仅显示一个pin,这与默认注释视图的行为相同,但所有注释都在显示,我无法找到隐藏它们的方法

有什么想法吗

谢谢

[编辑] 我目前对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;


}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
NSLog(“项目añadido”);
静态NSString*AnnotationViewID=@“AnnotationViewID”;
CustomMKAnnotationView*annotationView=
(CustomMKAnnotationView*)[mapa dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
如果(注释视图==nil)
{
annotationView=[[CustomMKAnnotationView alloc]initWithAnnotation:annotation重用标识符:AnnotationViewID]自动释放];
}
annotationView.annotation=注释;
返回注释视图;
}
因为我需要一个标准的气泡,但要有一个图像和几个标签。但我想保持标准的行为,也就是说,当气泡不出现时,有一个别针,当你点击它时,它会显示气泡。我的自定义气泡的内容在“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];

}
}
-(id)initWithAnnotation:(id)注释重用标识符:(NSString*)重用标识符{
self=[super initWithAnnotation:annotation-reuseIdentifier:reuseIdentifier];
if(self!=nil)
{
CGRect frame=self.frame;
frame.size=CGSizeMake(10.0,10.0);
self.frame=frame;
//self.=[超级pincolor];
self.backgroundColor=[UIColor clearColor];
self.centerOffset=CGPointMake(10.0,10.0);
}
回归自我;
}
-(void)drawRect:(CGRect)rect{
CustomMKAnnotation*custom=(CustomMKAnnotation*)self.annotation;
如果(自定义!=nil)
{   
NSLog(@“El nombre es:%@,[自定义名称]);
UILabel*nombre=[[UILabel alloc]init];
UILabel*媒体=[[UILabel alloc]init];
PDColoredProgressView*barrita=[[PDColoredProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
[barrita setTintColor:[UIColor颜色,红色:0.6绿色:0.83蓝色:0.91阿尔法:1.0f];
nombre.textColor=[UIColor-whiteColor];
media.textColor=[UIColor-whiteColor];
nombre.font=[UIFont fontWithName:@“DIN粗体”大小:14];
media.font=[UIFont fontWithName:@“DIN中等”大小:12];
CGSize size=[[custom nombre]sizeWithFont:nombre.font constrainedToSize:CGSizeMake(300,20)lineBreakMode:nombre.lineBreakMode];
NSLog(@“el ancho es:%f y alto%f”,尺寸.宽度,尺寸.高度);
nombre.backgroundColor=[UIColor clearColor];
media.backgroundColor=[UIColor clearColor];
nombre.text=[自定义nombre];
barrita.progress=[定制绅士];
media.text=[NSString stringWithFormat:@“media%@años”,[custom media]];
UIImageView*fondo=[[UIImageView alloc]initWithImage:[UIImageName:@“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,媒体帧原点y+20,尺寸宽度,10);
fondo.frame=CGRectMake(-(尺寸.宽度+20.0f)/2),-((尺寸.高度+10)*2+20)-10,尺寸.宽度+20.0f,(尺寸.高度+10)*2+20);
fondo.autoresizingMask=uiviewautoresizingflexibleleleftmargin;
nombre.autoresizingMask=uiviewAutoresizingflexibleleleftmargin;
[fondo addSubview:nombre];
[fondo addSubview:媒体];
[fondo addSubview:barrita];
[自添加子视图:fondo];
[丰多释放];
[名义释放];
[媒体发布];
}
}

如果您的意思是隐藏pin的详细信息,您是否尝试创建自定义的
MKPinAnnotationView
并将其属性设置为
canShowCallout=NO

在mapview委托方法中:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id    <MKAnnotation>)annotation
{

 MKPinAnnotationView*pinView;

if([annotation isKindOfClass:[<yourannotationclass> class]])
{

    static NSString*annoIdentifier=@"AnnotationIdentifier";

    pinView=(MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annoIdentifier];

    if(pinView==nil)
    {
        pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annoIdentifier]autorelease ];
    }

    pinView.animatesDrop=NO;
    pinView.canShowCallout=NO;
    pinView.pinColor=MKPinAnnotationColorRed;


}

   return pinView;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
MKPinAnnotationView*pinView;
if([annotation isKindOfClass:[class]])
{
静态NSString*AnnotationIdentifier=@“AnnotationIdentifier”;
pinView=(MKPinAnnotationView*)[mapView出列重用AnnotationViewWithIdentifier:AnnotIdentifier];
如果(pinView==nil)
{
pinView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:AnnotionIdentifier]autorelease];
}
pinView.animatesDrop=否;
pinView.canShowCallout=否;
pinView.pinColor=MKPinAnnotationColorRed;
}
返回pinView;
}

我添加了一些代码,使我的尝试更加清晰,这基本上模仿了annotationview的标准行为,但在我的自定义annotationview中,我需要管脚,以及那些在点击时显示气泡的管脚。很抱歉,我仍然不清楚您的问题,你有一个别针,当你点击它时,你会看到带有图片和细节的气泡?那么你到底需要什么呢?对不起,我现在会尽量说得更清楚。我粘贴的代码在地图中“绘制”气泡,没有图钉。气泡已展开,因此如果我有5个位置,则地图上会显示满是气泡。我需要一种类似于标准的行为。也就是说,它首先“绘制”管脚,当您点击任何管脚时,会显示我已经实现的自定义注释,其中包含多个UILabel和一个图像。当前的实现没有显示管脚,气泡已经展开。好的,我理解了,但是我使用
viewForAnnotation
中的自定义
MKPinAnnotationView
获取管脚,就像我粘贴的代码一样。你能不能试一下那段代码,如果你得到了PIN码,请告诉我。我试了你的代码,它抛出了一个错误。当它要添加第一个注释时。kindOfClass的第一个“if”为false,返回“pinView”。错误为“[MapViewController setAnnotation:]:已发送无法识别的选择器