2012-01-13 4 views
0

표준 주석처럼 정확하게 작동하는 사용자 정의 주석보기를 원하지만 내 이미지가 여러 텍스트에 있어야하므로 http://developer.apple.com/library/ios/#samplecode/WeatherMap/Introduction/Intro.html객관적인 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; 


} 

Becuase 나는 표준 거품 그러나 이미지와 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]; 

} 
} 

답변

1

당신이 핀의 세부 사항을 숨기는 의미하는 경우, 당신은 사용자 정의 MKPinAnnotationView을 만드는 시도하고 canShowCallout=NO;의 그것의 속성을 설정? 당신의지도보기 대리자 메서드에서

:

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

MKPinAnnotationView*pinView; 

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

    static NSString*[email protected]"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; 
} 
+0

나는 basicly입니다, 내가 핀을 필요로하는 annotationview의하지만 내 사용자 지정 주석보기 표준 동작을 모방하고있는 임하려고 무엇을 명확하게하기 위해 몇 가지 코드를 추가 도청 될 때 거품을 나타내는 핀들. – subharb

+0

미안하지만 아직도 문제가 명확하지 않다. 이미지와 세부 사항이있는 풍선을 클릭하면 핀이 생기게된다. 정확히 무엇이 필요합니까? – iNoob

+0

죄송합니다. 지금은 더 명확하게하려고 노력할 것입니다. 붙여 넣은 코드는 핀없이지도에 거품을 그립니다. 거품이 확장되므로 5 개의 위치가 있으면지도가 거품으로 가득 차 있습니다. 표준과 비슷한 동작이 필요합니다. 즉, 먼저 핀을 "뽑습니다". 핀 중 하나를 탭하면 이미 구현 한 사용자 정의 주석에 여러 개의 uilabels와 이미지가 포함됩니다. 현재 구현에서는 핀이 표시되지 않고 거품이 이미 확장되어 있습니다. – subharb