我正在使用当前位置图标的自定义标注(标题和副标题)。我尝试按照以下方法禁用默认注释,但它不起作用。
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
NSLog(@"viewForAnnotation");
if ([annotation isKindOfClass:[MKUserLocation class]])
{
MKAnnotationView *userLocationView = [mapView viewForAnnotation:annotation];
userLocationView.canShowCallout = NO;
NSLog(@"[annotation isKindOfClass:[MKUserLocation class]");
return nil;
}
}
唯一有效的方法是
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)ann
{
if([ann.annotation isKindOfClass:[MKUserLocation class]] )
{
[mymap deselectAnnotation:ann.annotation animated:NO];
}
}
但有时会滞后。还有其他方法可以禁用当前位置注释的默认标注视图吗?任何帮助将不胜感激。
要完成此操作,需要获取当前位置的参考MKAnnotationView
。人们可以在任何地方获取此参考,但最好在确定用户位置后立即获取它。
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKAnnotationView* annotationView = [mapView viewForAnnotation:userLocation];
annotationView.canShowCallout = NO;
}
或者使用下面的方法
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
MKAnnotationView *aV;
for (aV in views) {
if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
MKAnnotationView* annotationView = aV;
annotationView.canShowCallout = NO;
}
}
如果想在运行时更改 canShowCallout 属性,则可以使用以下
for (AnnotationClass* annotation in mapView.annotations)
{
if([annotation isKindOfClass:[MKUserLocation class]] )
{
MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
annotationView.canShowCallout = NO;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)