我能够通过在viewForAnnotation委托方法内的注释视图上调用“prepareForDisplay”来显示它。prepareForDisplay是iOS 11中的一种新方法,但没有文档记录。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
// Current Location Annotation
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
// Custom Annotation
if ([annotation isKindOfClass:[CustomAnnotationView class]]) {
CustomAnnotationView *view = (CustomAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Custom"];
if (!view) {
view = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Custom"];
} else {
view.annotation = annotation;
}
if (@available(iOS 11.0, *)) {
[view prepareForDisplay];
}
return view;
}
return nil;
}