首页 > 解决方案 > 自定义注释视图未显示在 iOS 12 的 MKMapView 中

问题描述

我有一个自定义注释视图类,就像

@interface MyAnnotationView : MKAnnotationView

@property (nonatomic, strong) UIImageView *imageView;

@end

然后我在 MKMapView 中使用它,例如:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    MKAnnotationView *annotationView = nil;
    MyAnnotationView *view = (MyAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:MyAnnotationViewIdentifier];
    if (view == nil) {
        view = [[MyAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MyAnnotationViewIdentifier];
    }
    view.imageView.image = myImage;
    annotationView = view;
    return annotationView;
}

此代码在 iOS 11 之前按预期工作,但在 iOS 12 中我不再看到该图像。我错过了什么?任何提示表示赞赏。

标签: iosobjective-cmapkitmkmapview

解决方案


推荐阅读