如何停止viewForAnnotation方法覆盖iOS中的默认用户位置蓝色信标

现在我用填充填充地图视图,并显示用户的当前位置.使用viewForAnnotation方法,它会使用认的红色引脚覆盖所有注释,但是我想返回其他注释的视图,但将用户位置保留为认的蓝色信标.有没有办法这样做,或者我必须创建一个新的注释视图,并根据注释返回正确的?

现在我有这样的东西:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if (annotation.coordinate == locationManager.location.coordinate) {

return nil;

    }else {

    MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Beacon"];

    // Button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeDetaildisclosure];
    button.frame = CGRectMake(0,23,23);
    annotationView.rightCalloutAccessoryView = button;


    annotationView.canShowCallout = YES;

    return annotationView;
}
}

但是我不能等于两个,因为我不能从坐标参数中获取坐标属性.

有谁知道任何解决方案吗?

解决方法

在这里查看文档:

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html

正如它所说:

If the object in the annotation parameter is an instance of the
MKUserLocation class,you can provide a custom view to denote the
user’s location. To display the user’s location using the default
system view,return nil.

所以你可以添加一个条件来检查:

if([annotation isKindOfClass: [MKUserLocation class]]) {
  return nil;
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...