Xcode 在UIMapView中放置插针和插针颜色失败

Xcode 在UIMapView中放置插针和插针颜色失败,xcode,mkmapview,Xcode,Mkmapview,我在地图视图上有点小问题 首先,无论我如何设置pin的颜色,它仍然是红色的 第二,没有插针的动画,插针只是与UIView一起出现 这是我的密码 多谢各位 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { self->mapView.mapType = MKMapTypeHybrid; CLLo

我在地图视图上有点小问题

首先,无论我如何设置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;       
}  
//实现viewDidLoad以在加载视图后执行附加设置,通常从nib加载。
-(无效)viewDidLoad{
self->mapView.mapType=MKMapTypeHybrid;
位置协调中心;
中心纬度=33.79518;
中心经度=130.92263;
//声明地图的跨度(高度和宽度以度为单位)
Mk坐标跨度;
span.latitudeDelta=.05;
span.longitudeDelta=.01;
//将“中心”和“跨度”添加到区域,
//调整区域以适合地图视图
//并指定给地图视图区域
协调区域;
region.center=中心;
region.span=span;
mapView.region=[mapView RegionAtfits:region];
transportfu*addAnnotation=[[transportfu alloc]initWithCoordinate:center];
[addAnnotation setTitle:@“城市”];
[addAnnotation setSubTitle:@“福冈”];
[地图视图添加注释:添加注释];
[超级视图下载];
mapView.showsUserLocation=是;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图用于注释:(id)注释{
MKPinAnnotationView*annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“MyPin”];
annView.canShowCallout=是;
[选择:是];
annView.pinColor=MKPinAnnotationColorGreen;
annView.calloutOffset=CGPointMake(-5,5);
annView.animatesDrop=是;
返回视图;
}  

您的
注释视图
方法需要一个出列方法

试试这个:

- (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;       
}  
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{  
静态NSString*MyAnnotationIdentifier=@“MyPin”;
MKPinAnnotationView*annView=
(MKPinAnnotationView*)[mapView出列可重用AnnotationViewWithIdentifier:MyAnnotationIdentifier];
如果(!annView)
{
annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“MyPin”];
annView.canShowCallout=是;
[选择:是];
annView.pinColor=MKPinAnnotationColorGreen;
annView.calloutOffset=CGPointMake(-5,5);
annView.animatesDrop=是;
}否则{
annView.annotation=注释;
}
返回视图;
}