如何阻止viewForAnnotation方法覆盖iOS中的默认用户位置蓝色信标 [英] How to stop the viewForAnnotation method from overriding the default user location blue beacon in iOS
问题描述
现在我正在使用注释填充地图视图,并显示用户的当前位置。使用viewForAnnotation方法,它会使用默认的红色引脚覆盖所有注释,但我想返回其他注释的视图,但将用户位置保留为默认的蓝色信标。有没有办法简单地做到这一点,还是我必须创建一个新的注释视图并根据注释返回正确的注释视图?
Right now I am populating a map view with annotations, and also displaying the user's current location. With the viewForAnnotation method, it overrides all annotations with the default red pin, but I want to return the views for the other annotations, but keep the user location the default blue beacon. Is there a way to do this simply or do I have to create a new annotation view and return the right one depending on the annotation?
现在我有类似的东西:
Right now I have something like:
- (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, 0, 23, 23);
annotationView.rightCalloutAccessoryView = button;
annotationView.canShowCallout = YES;
return annotationView;
}
}
但我无法将两者等同于因为我可以不要从注释参数中获取坐标属性。
But I can't equate the two because I can't get the coordinate property out of the annotation argument.
有人知道任何解决方案吗?
Anybody know any solutions to this?
推荐答案
查看此处的文档:
正如它所述:
如果注释中的对象参数是
MKUserLocation
类的实例,您可以提供自定义视图来表示
用户的位置。要使用默认的
系统视图显示用户的位置,请返回nil。
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.
因此您可以添加条件以进行检查这个:
So you can add a conditional to check for this:
if([annotation isKindOfClass: [MKUserLocation class]]) {
return nil;
}
这篇关于如何阻止viewForAnnotation方法覆盖iOS中的默认用户位置蓝色信标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!