【问题标题】:Drop pin and pin color failed in UIMapView在 UIMapView 中放置图钉和图钉颜色失败
【发布时间】:2011-12-09 20:23:13
【问题描述】:

我在 MapView 上遇到了一点问题。

首先,无论我如何设置图钉的颜色,它都是红色的。

其次,drop pin没有动画,pin只是和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;       
}  

【问题讨论】:

    标签: xcode mkmapview


    【解决方案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;       
    }  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多