2012-05-01 17 views
9

Jestem nowym użytkownikiem mapkit w funkcji -c. Jestem w stanie dodać niestandardową adnotację w widoku mapy.jak dodać niestandardowy widok objaśnienia w widoku mapy

muszę umieścić widok niestandardowy wywołania jak poniżej obrazu

like this.

Ale nie udało mi się zaprojektować widoku objaśnień w ten sposób.

Wiem, że potrzebuję dodać objaśnienie w widoku dla metody adnotacji.

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    static NSString *AnnotationViewID = @"annotationViewID"; 

    MKAnnotationView *annotationView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID]; 

    if (annotationView == nil) 
    { 
     annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease]; 
    } 

    annotationView.image = [UIImage imageNamed:@"blue_without_pin.png"]; 
    annotationView.annotation = annotation; 


    return annotationView; 
} 
+0

http://shawnsbits.com/blog/2011/04/12/custom-map-pins-for-mapkit/..visit tutaj .. – Nit

+0

dzięki za powtórkę, ale link, który wysłałeś, nie działa, nie pokazuje żadnych wyników. –

+0

http://shawnsbits.com/blog/2010/12/23/mapkit-overlays-session-1-overlay-map/ – hanumanDev

Odpowiedz

0

zasadzie to, co chcesz zrobić, to dodać nowy widok niestandardowy poprzez wdrożenie następującą metodę w swojej MKMapViewDelegate przykład:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { 
    CGPoint annotationCenter = [mapView convertCoordinate:view.annotation.coordinate toPointToView:mapView]; 
    [self displayCustomCalloutForAnnotation:view.annotation center:annotationCenter]; 
} 
0
@interface CustomAnnotaionView : MKAnnotationView 




@property (strong, nonatomic) UIView *calloutView; 




-(void)setSelected:(BOOL)selected animated:(BOOL)animated; 




@end 




@implementation CustomAnnotaionView 




@synthesize calloutView = _calloutView; 




-(void)setSelected:(BOOL)selected animated:(BOOL)animated 





{ 

    [super setSelected:selected animated:animated]; 

    if(selected) 
    { 

     [self.calloutView setFrame:CGRectMake(30, 130, 250, 135)]; 
     [self.calloutView sizeToFit]; 
     self.calloutView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"popup.png"]]; 
     [self addSubview:self.calloutView]; 

    } 
    else 
    { 

     [self.calloutView removeFromSuperview]; 
    } 

} 

-(void)didAddSubview:(UIView *)subview 
{ 

    if([[[subview class]description]isEqualToString:@"UICalloutView"]) 
    { 

     [subview removeFromSuperview]; 

    } 
} 

Use this customAnnotationView class in MapView delegate method, 

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id 

<MKAnnotation>)annotation 

{ 



    if([annotation isKindOfClass:[MapAnnotation class]]) 
    { 
     CustomAnnotationView *annotationView = (CustomAnnotaionView*)[theMapView dequeueReusableAnnotationViewWithIdentifier:@"CustomAnnotationView"]; 
     if(!annotationView) 
     { 
     MapAnnotation *annotation = (MapAnnotation *)annotation; 

     annotationView = [[CustomAnnotaionView alloc]initWithAnnotation:annotation reuseIdentifier:@"CustomAnnotationView"]; 

      [annotationView setCanShowCallout:YES]; 
     } 
     else 
      annotationView.annotation = annotation; 

     return annotationView; 

    } 
    return nil; 

} 
-3

musi wdrożyć objaśnienie zobaczyć siebie i używać

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 

tego uczestnika, aby widok objaśnienia był wyświetlany we właściwym miejscu,

IOS nie ma żadnego sposobu na widoku niestandardowego objaśnienia jeszcze

+1

Czym różnią się one od odpowiedzi @pnollet – Mark

0

Jednym rozwiązaniem byłoby wykryć dokładna współrzędna adnotacji wybranego stosunku do UIView macierzystej, a następnie rysując UIView bezpośrednio na górze MKMapView.

Oto fragment, który może pomóc:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    CGPoint pointInMap = [self.mapView convertCoordinate:buildingAnnotation.coordinate 
              toPointToView:self.view]; 

    // Hide the default callout generated by MKMapView 

    [mapView deselectAnnotation:view.annotation animated:NO]; 

    // Create a custom callout view and center the arrow on the pointInMap CGPoint 
} 
Powiązane problemy