我有一个奇怪的行为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;
}
Run Code Online (Sandbox Code Playgroud)
请务必避免为内置用户位置标记提供注释视图.
- (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;
}
Run Code Online (Sandbox Code Playgroud)
通过先检查用户位置注释,您可以提前返回nil而不是分配新的MKPinAnnotationView并返回它.
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation各州的文件:
如果annotation参数中的对象是MKUserLocation类的实例,则可以提供自定义视图来表示用户的位置.要使用默认系统视图显示用户的位置,请返回nil.
| 归档时间: |
|
| 查看次数: |
3143 次 |
| 最近记录: |