代码之家  ›  专栏  ›  技术社区  ›  iLearner damithH

iOS 11中未显示MKAnnotationView

  •  5
  • iLearner damithH  · 技术社区  · 9 年前

    未显示MKAnnotationView (只有iOS 11才会出现这种情况)。

    我去看了苹果的文档,但API中并没有任何这样的贬损,但它仍然不起作用。

    有人能帮我解决这个问题吗。

    1 回复  |  直到 8 年前
        1
  •  10
  •   rosem    9 年前

    我能够通过在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;
    }
    

    推荐文章