iOS:用户位置变为pin

iOS:用户位置变为pin,第1张

概述我有一个奇怪的行为mapView:当我打开它,一切正常.将找到用户(蓝色圆圈)并且3个针脚就位.但是(我不知道为什么)一段时间后,蓝点变成了一个引脚 – 但只有当我的连接速度很慢时才会这样. 这是我得到的: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotati 我有一个奇怪的行为mapVIEw:当我打开它,一切正常.将找到用户(蓝色圆圈)并且3个针脚就位.但是(我不知道为什么)一段时间后,蓝点变成了一个引脚 – 但只有当我的连接速度很慢时才会这样.

这是我得到的:

- (MKAnnotationVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID <MKAnnotation>)annotation{    MKPinAnnotationVIEw *pinVIEw = (MKPinAnnotationVIEw *)[mapVIEw dequeueReusableAnnotationVIEwWithIDentifIEr:@"pinVIEw"];    if (!pinVIEw && ![annotation isKindOfClass:[MKUserLocation class]])    {        pinVIEw = [[MKPinAnnotationVIEw alloc] initWithAnnotation:annotation reuseIDentifIEr:@"pinVIEw"];        pinVIEw.pincolor = MKPinAnnotationcolorRed;        pinVIEw.animatesDrop = YES;        pinVIEw.canShowCallout = YES;        UIbutton *rightbutton = [UIbutton buttonWithType:UIbuttonTypeDetaildisclosure];        pinVIEw.rightCalloutAccessoryVIEw = rightbutton;        if (annotation == self.locationZH1)        {            [pinVIEw setTag:1];        }        else if (annotation == self.locationZH2)        {            [pinVIEw setTag:2];        }        else if (annotation == self.locationZH3)        {            [pinVIEw setTag:3];        }        else if (annotation == self.locationLU1)        {            [pinVIEw setTag:4];        }    }    else    {        pinVIEw.annotation = annotation;    }    return pinVIEw;}
解决方法 请务必避免为内置用户位置标记提供注释视图.

- (MKAnnotationVIEw *)mapVIEw:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID<MKAnnotation>)annotation{    //check annotation is not user location    if([annotation isEqual:[mapVIEw userLocation]])    {        //bail        return nil;    }    static Nsstring *annotationVIEwReuseIDentifer = @"map_vIEw_annotation";    //dequeue annotation vIEw    MKPinAnnotationVIEw *annotationVIEw = (MKPinAnnotationVIEw *)[mapVIEw dequeueReusableAnnotationVIEwWithIDentifIEr:annotationVIEwReuseIDentifer];    if(!annotationVIEw)    {        annotationVIEw = [[MKPinAnnotationVIEw alloc] initWithAnnotation:annotation reuseIDentifIEr:annotationVIEwReuseIDentifer];    }    //set annotation vIEw propertIEs    [annotationVIEw setAnnotation:annotation];    return annotationVIEw;}

通过先检查用户位置注释,您可以提前返回nil而不是分配新的MKPinAnnotationVIEw并返回它.

– (MKAnnotationVIEw *)mapVIEw的文档:(MKMapVIEw *)mapVIEw vIEwForAnnotation:(ID< MKAnnotation>)注释状态:

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.

总结

以上是内存溢出为你收集整理的iOS:用户位置变为pin全部内容,希望文章能够帮你解决iOS:用户位置变为pin所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1006214.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存