2011-12-09 40 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