Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c MKPinAnnotationView自定义图像将替换为带有动画拖放的pin_Objective C_Ios_Mkmapview_Mkpinannotationview - Fatal编程技术网

Objective c MKPinAnnotationView自定义图像将替换为带有动画拖放的pin

Objective c MKPinAnnotationView自定义图像将替换为带有动画拖放的pin,objective-c,ios,mkmapview,mkpinannotationview,Objective C,Ios,Mkmapview,Mkpinannotationview,我正在地图视图上显示用户头像图像。如果在没有动画的情况下渲染化身,那么它们似乎可以工作,但是我想为它们的下落设置动画。如果我将pinView.animatesDrop设置为true,那么我将丢失头像,并将其替换为pin。我如何在不使用pin的情况下设置我的化身下落的动画 以下是我正在使用的viewForAnnotation方法: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnot

我正在地图视图上显示用户头像图像。如果在没有动画的情况下渲染化身,那么它们似乎可以工作,但是我想为它们的下落设置动画。如果我将pinView.animatesDrop设置为true,那么我将丢失头像,并将其替换为pin。我如何在不使用pin的情况下设置我的化身下落的动画

以下是我正在使用的viewForAnnotation方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    MKPinAnnotationView* pinView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"MyAnnotation"];

    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"];
    }
    else
        pinView.annotation = annotation;

    //If I set this to true, my image is replaced by the pin
    //pinView.animatesDrop = true;

    //I'm using SDWebImage
    [pinView setImageWithURL:[NSURL URLWithString:@"/pathtosomeavatar.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    //Adding a nice drop shadow here
    pinView.layer.shadowColor = [UIColor blackColor].CGColor;
    pinView.layer.shadowOffset = CGSizeMake(0, 1);
    pinView.layer.shadowOpacity = 0.5;
    pinView.layer.shadowRadius = 3.0;

    return pinView;
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释{
if([annotation isKindOfClass:[MKUserLocation类]])
返回零;
MKPinAnnotationView*pinView=(MKPinAnnotationView*)[self.mapView dequeuereusableannotationview with identifier:@“MyAnnotation”];
如果(!pinView){
pinView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:@“CustomPinAnnotation”];
}
其他的
pinView.annotation=注释;
//如果我将此设置为true,则我的图像将替换为pin
//pinView.animatesDrop=true;
//我正在使用SDWebImage
[pinView setImageWithURL:[NSURL URLWithString:@”/pathtosomeavatar.png“]占位符图像:[UIImage ImageName:@“placeholder.png”];
//在这里添加一个漂亮的阴影
pinView.layer.shadowColor=[UIColor blackColor].CGColor;
pinView.layer.shadowOffset=CGSizeMake(0,1);
pinView.layer.shadowOpacity=0.5;
pinView.layer.shadowRadius=3.0;
返回pinView;
}

当您想将自己的图像用于注释视图时,最好创建一个常规的
MKAnnotationView
而不是
MKPinAnnotationView

由于
MKPinAnnotationView
MKAnnotationView
的子类,因此它有一个
image
属性,但它通常(通常在您不期望的情况下)会忽略它并显示其内置的pin图像

因此,与其与之抗争,最好只使用普通的
MKAnnotationView

如果不使用
MKPinAnnotationView
,最大的损失就是内置的拖放动画,您必须手动实现

有关更多详细信息,请参见前面的回答:

如果您在这个问题上遇到了障碍,并且您确信自己是
MKAnnotationView
而不是
MKPinAnnotationView
,请确保您的
MKMapView
的委托属性没有被禁用。

请查看Anna的链接以回答我的问题。安娜,请把你的评论作为一个答案,这样我才能相信你。