为当前位置注释设置canShowCallOut = NO,iPhone [英] setting canShowCallOut = NO for current location annotation, iPhone

查看:756
本文介绍了为当前位置注释设置canShowCallOut = NO,iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用当前位置图标的自定义调出(标题和副标题)。我尝试了以下来禁用默认注释,但它不起作用。

I am using custom call out (title and subtitle)for Current location icon. I tried following to disable default annotation but it does not work.

- (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];
    }
}

但有时会滞后。是否有其他方法可以禁用当前位置注释的默认标注视图?任何帮助将不胜感激。

But it lags sometimes. Is there other way do disable default callout view for current location annotation? Any help will be appreciated.

推荐答案

要完成此任务,需要获取当前位置的参考 MKAnnotationView 。可以在任何地方获得此引用,但最好在确定用户位置后立即获取。

To get this done one need to get reference of current location MKAnnotationView. One can get this reference anywhere but it is better to get it as soon as user location is determined.

- (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中更改在运行时的属性然后可以使用以下

and if want to change in canShowCallout property in runtime then one can use following

for (AnnotationClass* annotation in mapView.annotations) 
    {
        if([annotation isKindOfClass:[MKUserLocation class]] )
        {
             MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
             annotationView.canShowCallout = NO;
        }
    }

这篇关于为当前位置注释设置canShowCallOut = NO,iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆