2011-12-09 4 views
0

MapView에서 약간의 문제가 있습니다.UIMapView에서 핀 및 핀 색상이 떨어졌습니다.

우선, 핀의 색상을 어떻게 설정하든 관계없이 빨간색으로 유지됩니다.

둘째, 드롭 핀의 어떤 애니메이션이없는, 핀은 여기 내 코드입니다 UIView의

과 함께 나타납니다.

대단히 감사합니다.

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 

    self->mapView.mapType = MKMapTypeHybrid; 
    CLLocationCoordinate2D center; 
    center.latitude = 33.79518; 
    center.longitude = 130.92263; 

    //declare span of map (height and width in degrees) 
    MKCoordinateSpan span; 
    span.latitudeDelta = .05; 
    span.longitudeDelta = .01; 

    //add center and span to a region, 
    //adjust the region to fit in the mapview 
    //and assign to mapview region 
    MKCoordinateRegion region; 
    region.center = center; 
    region.span = span; 
    mapView.region = [mapView regionThatFits:region]; 
    transportfu *addAnnotation = [[transportfu alloc] initWithCoordinate:center]; 
    [addAnnotation setTitle:@"City"]; 
    [addAnnotation setSubTitle:@"Fukuoka"]; 

    [mapView addAnnotation:addAnnotation]; 
    [super viewDidLoad]; 
    mapView.showsUserLocation = YES; 
} 

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"]; 

    annView.canShowCallout = YES; 
    [annView setSelected:YES]; 
    annView.pinColor = MKPinAnnotationColorGreen; 
    annView.calloutOffset = CGPointMake(-5, 5); 
    annView.animatesDrop=YES; 
    return annView;  
} 

답변

1

귀하의 viewForAnnotation 방법은 디큐 방법이 필요합니다.

이 시도 :

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation 
{ 
    static NSString *MyAnnotationIdentifier = @"MyPin"; 
    MKPinAnnotationView *annView = 
    (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:MyAnnotationIdentifier]; 
    if (!annView) 
    { 
     annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"]; 

     annView.canShowCallout = YES; 
     [annView setSelected:YES]; 
     annView.pinColor = MKPinAnnotationColorGreen; 
     annView.calloutOffset = CGPointMake(-5, 5); 
     annView.animatesDrop=YES; 
    } else { 
     annView.annotation = annotation; 
    } 
    return annView;  
} 
+0

감사합니다! 이제 작동 중입니다! – Clarence