下面的代码是显示自定义引脚(图片为引脚)。可以正常使用。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
PVAttractionAnnotationView *annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Attraction"];
annotationView.canShowCallout = YES;
return annotationView;
}
然后使用下面的代码显示当前位置
[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];
XCODE跳转到main.m并显示
Thread 1:Signal SIGABRT
另一方面,如果我使用下面的代码
[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];
并且未使用以下所有代码
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
PVAttractionAnnotationView *annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Attraction"];
annotationView.canShowCallout = YES;
return annotationView;
}
应用程序 将正常显示当前位置,但不会显示自定义 pin。它显示的是系统默认的红色引脚,因为我没有使用该代码。
如何制作自定义图钉并同时使用 FollowWithHeading
模式?
..抱歉我英语不好。
最佳答案
您需要对检查注释类并返回适当 View 的 viewForAnnotation
稍作更改。通过返回 nil,系统将使用默认 View 。您还需要一些额外的代码来正确实现 View 重用 -
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *annotationView=nil;
if ([annotation isKindOfClass:[PVAttractionAnnotation class]]) // Note - put your custom annotation class here
{
annotationView =(MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Attraction"];
if (annotationView == nil)
{
annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Attraction"];
annotationView.canShowCallout = YES;
}
else
{
annotationView.annotation=annotation;
}
}
return annotationView;
}
关于ios - 如何制作自定义图钉并同时使用 FollowWithHeading 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22947722/