我正在应用商店上运行一个应用程序,该应用程序具有带有其他功能的 map View 。
在iOS 10(iOS 11以外的所有版本)之前,一切都可以正常运行,现在当我在iOS 11上测试相同的应用程序时,不会显示 MKAnnotationView(这仅在iOS 11上发生)。
没有显示任何异常/错误。
我曾想过苹果文档,但是API中没有任何过时的规定,但仍然无法正常工作。
有人可以帮我解决这个问题。
最佳答案
我可以通过在viewForAnnotation委托(delegate)方法内的注释 View 上调用“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;
}
我仍在尝试找出这是错误还是正确使用。敬请关注!
关于annotations - MKAnnotationView没有在iOS 11中显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46320999/